Message ID | 1641996862-26960-4-git-send-email-akhilrajeev@nvidia.com |
---|---|
State | Superseded |
Headers | show |
Series | Enable named interrupt smbus-alert for ACPI | expand |
On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote: > > Change of_*() functions to device_*() for firmware agnostic usage. > This allows to have smbus_alert interrupt without any changes the smbus_alert > in the controller drivers using ACPI table. the ACPI ... This change reveals potential issue: > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > + irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert"); > if (irq <= 0) I guess this '= 0' part should be fixed first. > return irq;
> On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote: > > > > Change of_*() functions to device_*() for firmware agnostic usage. > > This allows to have smbus_alert interrupt without any changes > > the smbus_alert > > > in the controller drivers using ACPI table. > > the ACPI > > ... > > This change reveals potential issue: > > > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > > + irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert"); > > > if (irq <= 0) > > I guess this '= 0' part should be fixed first. '0' is a failure as per the documentation of of_irq_get_byname() as well as of_irq_get(). The case is different for acpi_irq_get(), but it is handled in fwnode_irq_get(). If I understood it right, a return value of '0' should be considered a failure here. Thanks, Akhil
On Thu, Jan 20, 2022 at 11:48 AM Akhil R <akhilrajeev@nvidia.com> wrote: > > On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote: ... > > This change reveals potential issue: > > > > > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > > > + irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert"); > > > > > if (irq <= 0) > > > > I guess this '= 0' part should be fixed first. > > '0' is a failure as per the documentation of of_irq_get_byname() as well as > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in > fwnode_irq_get(). If I understood it right, a return value of '0' should be > considered a failure here. Depends. I have no idea what the original code does here. But returning an error or 0 from this function seems confusing to me.
> ... > > > > This change reveals potential issue: > > > > > > > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > > > > + irq = device_irq_get_byname(adapter->dev.parent, > "smbus_alert"); > > > > > > > if (irq <= 0) > > > > > > I guess this '= 0' part should be fixed first. > > > > '0' is a failure as per the documentation of of_irq_get_byname() as well as > > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in > > fwnode_irq_get(). If I understood it right, a return value of '0' should be > > considered a failure here. > > Depends. I have no idea what the original code does here. But > returning an error or 0 from this function seems confusing to me. > The description in of_irq_get*() says - /* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case * of any other failure. */ As I see from the code of fwnode_irq_get(), which is used in this case, returns either the return value of of_irq_get() or error code from acpi_irq_get() when it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless there is an error. Thanks, Akhil
On Thu, Jan 20, 2022 at 12:29 PM Akhil R <akhilrajeev@nvidia.com> wrote: > > > ... > > > > > > This change reveals potential issue: > > > > > > > > > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > > > > > + irq = device_irq_get_byname(adapter->dev.parent, > > "smbus_alert"); > > > > > > > > > if (irq <= 0) > > > > > > > > I guess this '= 0' part should be fixed first. > > > > > > '0' is a failure as per the documentation of of_irq_get_byname() as well as > > > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in > > > fwnode_irq_get(). If I understood it right, a return value of '0' should be > > > considered a failure here. > > > > Depends. I have no idea what the original code does here. But > > returning an error or 0 from this function seems confusing to me. > > > The description in of_irq_get*() says - > /* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or > * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case > * of any other failure. > */ > As I see from the code of fwnode_irq_get(), which is used in this case, returns > either the return value of of_irq_get() or error code from acpi_irq_get() when > it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless > there is an error. of_irq_get*() seems inconsistent... Uwe, what do you think?
> > > ... > > > > > > > > This change reveals potential issue: > > > > > > > > > > > - irq = of_irq_get_byname(adapter->dev.of_node, > "smbus_alert"); > > > > > > + irq = > > > > > > + device_irq_get_byname(adapter->dev.parent, > > > "smbus_alert"); > > > > > > > > > > > if (irq <= 0) > > > > > > > > > > I guess this '= 0' part should be fixed first. > > > > > > > > '0' is a failure as per the documentation of of_irq_get_byname() > > > > as well as of_irq_get(). The case is different for acpi_irq_get(), > > > > but it is handled in fwnode_irq_get(). If I understood it right, a > > > > return value of '0' should be considered a failure here. > > > > > > Depends. I have no idea what the original code does here. But > > > returning an error or 0 from this function seems confusing to me. > > > > > The description in of_irq_get*() says - > > /* Return: Linux IRQ number on success, or 0 on the IRQ mapping > > failure, or > > * -EPROBE_DEFER if the IRQ domain is not yet created, or error code > > in case > > * of any other failure. > > */ > > As I see from the code of fwnode_irq_get(), which is used in this > > case, returns either the return value of of_irq_get() or error code > > from acpi_irq_get() when it fails, or res.start if it didn't fail. I > > guess, any of these would not be 0 unless there is an error. > > of_irq_get*() seems inconsistent... > > Uwe, what do you think? > A bit tricky. You are right, as we don't often see a return value of '0' as an error in Linux. But here since it is a number which is expected, it might be reasonable to allot 0 to an error as well. Not sure of the exact rationale in those functions though. Thanks, Akhil
On Thu, Jan 20, 2022 at 12:43:02PM +0200, Andy Shevchenko wrote: > On Thu, Jan 20, 2022 at 12:29 PM Akhil R <akhilrajeev@nvidia.com> wrote: > > > > > ... > > > > > > > > This change reveals potential issue: > > > > > > > > > > > - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); > > > > > > + irq = device_irq_get_byname(adapter->dev.parent, > > > "smbus_alert"); > > > > > > > > > > > if (irq <= 0) > > > > > > > > > > I guess this '= 0' part should be fixed first. > > > > > > > > '0' is a failure as per the documentation of of_irq_get_byname() as well as > > > > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in > > > > fwnode_irq_get(). If I understood it right, a return value of '0' should be > > > > considered a failure here. > > > > > > Depends. I have no idea what the original code does here. But > > > returning an error or 0 from this function seems confusing to me. > > > > > The description in of_irq_get*() says - > > /* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or > > * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case > > * of any other failure. > > */ > > As I see from the code of fwnode_irq_get(), which is used in this case, returns > > either the return value of of_irq_get() or error code from acpi_irq_get() when > > it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless > > there is an error. > > of_irq_get*() seems inconsistent... > > Uwe, what do you think? Yeah, this is something I stumbled over during the platform_get_irq*() discussion. But I don't feel like investing any more energy there. Best regards Uwe
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 1072a47..8e6c7a1 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1574,7 +1574,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) goto out_list; } - res = of_i2c_setup_smbus_alert(adap); + res = i2c_setup_smbus_alert(adap); if (res) goto out_reg; diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index e5b2d14..4c24c84 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -701,13 +701,13 @@ struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter, } EXPORT_SYMBOL_GPL(i2c_new_smbus_alert_device); -#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) -int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter) +#if IS_ENABLED(CONFIG_I2C_SMBUS) +int i2c_setup_smbus_alert(struct i2c_adapter *adapter) { int irq; - irq = of_property_match_string(adapter->dev.of_node, "interrupt-names", - "smbus_alert"); + irq = device_property_match_string(adapter->dev.parent, "interrupt-names", + "smbus_alert"); if (irq == -EINVAL || irq == -ENODATA) return 0; else if (irq < 0) @@ -715,5 +715,5 @@ int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter) return PTR_ERR_OR_ZERO(i2c_new_smbus_alert_device(adapter, NULL)); } -EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert); +EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); #endif diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index d3d06e3..fdd6d97 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -128,7 +128,7 @@ static int smbalert_probe(struct i2c_client *ara, if (setup) { irq = setup->irq; } else { - irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); + irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert"); if (irq <= 0) return irq; } diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h index 1ef4218..95cf902 100644 --- a/include/linux/i2c-smbus.h +++ b/include/linux/i2c-smbus.h @@ -30,10 +30,10 @@ struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter, struct i2c_smbus_alert_setup *setup); int i2c_handle_smbus_alert(struct i2c_client *ara); -#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) -int of_i2c_setup_smbus_alert(struct i2c_adapter *adap); +#if IS_ENABLED(CONFIG_I2C_SMBUS) +int i2c_setup_smbus_alert(struct i2c_adapter *adap); #else -static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) +static inline int i2c_setup_smbus_alert(struct i2c_adapter *adap) { return 0; }
Change of_*() functions to device_*() for firmware agnostic usage. This allows to have smbus_alert interrupt without any changes in the controller drivers using ACPI table. Signed-off-by: Akhil R <akhilrajeev@nvidia.com> --- drivers/i2c/i2c-core-base.c | 2 +- drivers/i2c/i2c-core-smbus.c | 10 +++++----- drivers/i2c/i2c-smbus.c | 2 +- include/linux/i2c-smbus.h | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-)