diff mbox series

[3/4] iio: backend: make use of dev_errp_probe()

Message ID 20240404-dev-add_dev_errp_probe-v1-3-d18e3eb7ec3f@analog.com (mailing list archive)
State Changes Requested
Headers show
Series dev_printk: add dev_errp_probe() helper | expand

Commit Message

Nuno Sa April 4, 2024, 11:06 a.m. UTC
Using dev_errp_probe() to simplify the code.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/industrialio-backend.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Andy Shevchenko April 4, 2024, 12:23 p.m. UTC | #1
On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:
> Using dev_errp_probe() to simplify the code.

...

> +	if (IS_ERR(fwnode))
> +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> +				      "Cannot get Firmware reference\n");

ERR_CAST() seems quite good candidate to have here.

		return dev_errp_probe(dev, fwnode, "Cannot get Firmware reference\n");

(Assuming dev_errp_probe() magically understands that, note you may have it as
 a macro and distinguish parameter type with _Generic() or so and behave
 differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
 implementation, but also keep in mind that it doesn't distinguish NULL/0, there
 is a patch available in the mailing list to fix that, though.)
Nuno Sá April 4, 2024, 2:58 p.m. UTC | #2
On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:
> On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:
> > Using dev_errp_probe() to simplify the code.
> 
> ...
> 
> > +	if (IS_ERR(fwnode))
> > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > +				      "Cannot get Firmware reference\n");
> 
> ERR_CAST() seems quite good candidate to have here.
> 
> 		return dev_errp_probe(dev, fwnode, "Cannot get Firmware
> reference\n");
> 
> (Assuming dev_errp_probe() magically understands that, note you may have it as
>  a macro and distinguish parameter type with _Generic() or so and behave
>  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
>  implementation, but also keep in mind that it doesn't distinguish NULL/0,
> there
>  is a patch available in the mailing list to fix that, though.)
> 

Do we care that much for going with that trouble? I understand like this we go
PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is not a
fastpath. So perhaps we could just keep it simple?

- Nuno Sá
Andy Shevchenko April 4, 2024, 3:12 p.m. UTC | #3
On Thu, Apr 04, 2024 at 04:58:27PM +0200, Nuno Sá wrote:
> On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:
> > On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:
> > > Using dev_errp_probe() to simplify the code.

...

> > > +	if (IS_ERR(fwnode))
> > > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > > +				      "Cannot get Firmware reference\n");
> > 
> > ERR_CAST() seems quite good candidate to have here.
> > 
> > 		return dev_errp_probe(dev, fwnode, "Cannot get Firmware
> > reference\n");
> > 
> > (Assuming dev_errp_probe() magically understands that, note you may have it as
> >  a macro and distinguish parameter type with _Generic() or so and behave
> >  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
> >  implementation, but also keep in mind that it doesn't distinguish NULL/0,
> > there
> >  is a patch available in the mailing list to fix that, though.)
> 
> Do we care that much for going with that trouble?

I don't think we do. We are not supposed to be called with ret == 0/NULL.
That's why I pointed out to the current version.

> I understand like this we go
> PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is not a
> fastpath. So perhaps we could just keep it simple?

It's not about performance, it's about readability. See the difference between
yours and mine.
Jonathan Cameron April 6, 2024, 4:07 p.m. UTC | #4
On Thu, 4 Apr 2024 18:12:25 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Thu, Apr 04, 2024 at 04:58:27PM +0200, Nuno Sá wrote:
> > On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:  
> > > On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:  
> > > > Using dev_errp_probe() to simplify the code.  
> 
> ...
> 
> > > > +	if (IS_ERR(fwnode))
> > > > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > > > +				      "Cannot get Firmware reference\n");  
> > > 
> > > ERR_CAST() seems quite good candidate to have here.
> > > 
> > > 		return dev_errp_probe(dev, fwnode, "Cannot get Firmware
> > > reference\n");
> > > 
> > > (Assuming dev_errp_probe() magically understands that, note you may have it as
> > >  a macro and distinguish parameter type with _Generic() or so and behave
> > >  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
> > >  implementation, but also keep in mind that it doesn't distinguish NULL/0,
> > > there
> > >  is a patch available in the mailing list to fix that, though.)  
> > 
> > Do we care that much for going with that trouble?  
> 
> I don't think we do. We are not supposed to be called with ret == 0/NULL.
> That's why I pointed out to the current version.
> 
> > I understand like this we go
> > PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is not a
> > fastpath. So perhaps we could just keep it simple?  
> 
> It's not about performance, it's about readability. See the difference between
> yours and mine.
> 

You are suggesting making it transparently take an error ptr or an integer?
Whilst clever, I'm not seeing that as a good idea for readability / reviewability.
I expect something that looks like a function to take the same parameters (other vargs)
always.  _Generic messes with that.

Maybe I just don't like to learn new things!  If consensus comes down in favour
of _Generic trickery then I'll get used to it eventually.

Jonathan
Andi Shyti April 6, 2024, 6:54 p.m. UTC | #5
Hi,

On Sat, Apr 06, 2024 at 05:07:17PM +0100, Jonathan Cameron wrote:
> On Thu, 4 Apr 2024 18:12:25 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > On Thu, Apr 04, 2024 at 04:58:27PM +0200, Nuno Sá wrote:
> > > On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:  
> > > > On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:  
> > > > > Using dev_errp_probe() to simplify the code.  
> > 
> > ...
> > 
> > > > > +	if (IS_ERR(fwnode))
> > > > > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > > > > +				      "Cannot get Firmware reference\n");  
> > > > 
> > > > ERR_CAST() seems quite good candidate to have here.
> > > > 
> > > > 		return dev_errp_probe(dev, fwnode, "Cannot get Firmware
> > > > reference\n");
> > > > 
> > > > (Assuming dev_errp_probe() magically understands that, note you may have it as
> > > >  a macro and distinguish parameter type with _Generic() or so and behave
> > > >  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
> > > >  implementation, but also keep in mind that it doesn't distinguish NULL/0,
> > > > there
> > > >  is a patch available in the mailing list to fix that, though.)  
> > > 
> > > Do we care that much for going with that trouble?  
> > 
> > I don't think we do. We are not supposed to be called with ret == 0/NULL.
> > That's why I pointed out to the current version.
> > 
> > > I understand like this we go
> > > PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is not a
> > > fastpath. So perhaps we could just keep it simple?  
> > 
> > It's not about performance, it's about readability. See the difference between
> > yours and mine.
> > 
> 
> You are suggesting making it transparently take an error ptr or an integer?
> Whilst clever, I'm not seeing that as a good idea for readability / reviewability.
> I expect something that looks like a function to take the same parameters (other vargs)
> always.  _Generic messes with that.
> 
> Maybe I just don't like to learn new things!  If consensus comes down in favour
> of _Generic trickery then I'll get used to it eventually.

the whole point of the dev_err_...() functions is to add trickery
in order to reduce code and brackets.

The way I see this is to have a combination of functions:

 - takes integer, returns integer -> dev_err_probe()
 - takes integer, returns pointer -> dev_errp_probe() (or dev_err_ptr_probe())
 - takes pointer, return integer -> ? dev_ptr_err_probe()
 - takes pointer, returns pointer -> ? dev_ptr_probe()

Thoughts?

Andi
Nuno Sá April 8, 2024, 9:01 a.m. UTC | #6
On Sat, 2024-04-06 at 17:07 +0100, Jonathan Cameron wrote:
> On Thu, 4 Apr 2024 18:12:25 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > On Thu, Apr 04, 2024 at 04:58:27PM +0200, Nuno Sá wrote:
> > > On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:  
> > > > On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:  
> > > > > Using dev_errp_probe() to simplify the code.  
> > 
> > ...
> > 
> > > > > +	if (IS_ERR(fwnode))
> > > > > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > > > > +				      "Cannot get Firmware
> > > > > reference\n");  
> > > > 
> > > > ERR_CAST() seems quite good candidate to have here.
> > > > 
> > > > 		return dev_errp_probe(dev, fwnode, "Cannot get Firmware
> > > > reference\n");
> > > > 
> > > > (Assuming dev_errp_probe() magically understands that, note you may have
> > > > it as
> > > >  a macro and distinguish parameter type with _Generic() or so and behave
> > > >  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
> > > >  implementation, but also keep in mind that it doesn't distinguish
> > > > NULL/0,
> > > > there
> > > >  is a patch available in the mailing list to fix that, though.)  
> > > 
> > > Do we care that much for going with that trouble?  
> > 
> > I don't think we do. We are not supposed to be called with ret == 0/NULL.
> > That's why I pointed out to the current version.
> > 
> > > I understand like this we go
> > > PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is not
> > > a
> > > fastpath. So perhaps we could just keep it simple?  
> > 
> > It's not about performance, it's about readability. See the difference
> > between
> > yours and mine.
> > 
> 
> You are suggesting making it transparently take an error ptr or an integer?
> Whilst clever, I'm not seeing that as a good idea for readability /
> reviewability.
> I expect something that looks like a function to take the same parameters
> (other vargs)
> always.  _Generic messes with that.

> Maybe I just don't like to learn new things!  If consensus comes down in
> favour
> of _Generic trickery then I'll get used to it eventually.
> 

Yeah, I agree with the above. Not fully convinced but for the ERR_CAST() case I
would very much prefer to have another explicit helper rather than hiding stuff
in the same macro.

- Nuno Sá
Nuno Sá April 8, 2024, 9:05 a.m. UTC | #7
On Sat, 2024-04-06 at 20:54 +0200, Andi Shyti wrote:
> Hi,
> 
> On Sat, Apr 06, 2024 at 05:07:17PM +0100, Jonathan Cameron wrote:
> > On Thu, 4 Apr 2024 18:12:25 +0300
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > 
> > > On Thu, Apr 04, 2024 at 04:58:27PM +0200, Nuno Sá wrote:
> > > > On Thu, 2024-04-04 at 15:23 +0300, Andy Shevchenko wrote:  
> > > > > On Thu, Apr 04, 2024 at 01:06:25PM +0200, Nuno Sa wrote:  
> > > > > > Using dev_errp_probe() to simplify the code.  
> > > 
> > > ...
> > > 
> > > > > > +	if (IS_ERR(fwnode))
> > > > > > +		return dev_errp_probe(dev, PTR_ERR(fwnode),
> > > > > > +				      "Cannot get Firmware
> > > > > > reference\n");  
> > > > > 
> > > > > ERR_CAST() seems quite good candidate to have here.
> > > > > 
> > > > > 		return dev_errp_probe(dev, fwnode, "Cannot get
> > > > > Firmware
> > > > > reference\n");
> > > > > 
> > > > > (Assuming dev_errp_probe() magically understands that, note you may
> > > > > have it as
> > > > >  a macro and distinguish parameter type with _Generic() or so and
> > > > > behave
> > > > >  differently: ERR_PTR() vs. ERR_CAST(), see acpi_dev_hid_uid_match()
> > > > >  implementation, but also keep in mind that it doesn't distinguish
> > > > > NULL/0,
> > > > > there
> > > > >  is a patch available in the mailing list to fix that, though.)  
> > > > 
> > > > Do we care that much for going with that trouble?  
> > > 
> > > I don't think we do. We are not supposed to be called with ret == 0/NULL.
> > > That's why I pointed out to the current version.
> > > 
> > > > I understand like this we go
> > > > PTR_ERR() to then comeback to ERR_PTR() but this for probe() which is
> > > > not a
> > > > fastpath. So perhaps we could just keep it simple?  
> > > 
> > > It's not about performance, it's about readability. See the difference
> > > between
> > > yours and mine.
> > > 
> > 
> > You are suggesting making it transparently take an error ptr or an integer?
> > Whilst clever, I'm not seeing that as a good idea for readability /
> > reviewability.
> > I expect something that looks like a function to take the same parameters
> > (other vargs)
> > always.  _Generic messes with that.
> > 
> > Maybe I just don't like to learn new things!  If consensus comes down in
> > favour
> > of _Generic trickery then I'll get used to it eventually.
> 
> the whole point of the dev_err_...() functions is to add trickery
> in order to reduce code and brackets.
> 

I'm not sure I'm completely convinced on having more helpers but also no strong
opinion tbh. But see below...

> The way I see this is to have a combination of functions:
> 
>  - takes integer, returns integer -> dev_err_probe()
>  - takes integer, returns pointer -> dev_errp_probe() (or dev_err_ptr_probe())
>  - takes pointer, return integer -> ? dev_ptr_err_probe()

This is pretty much all the dev_err_probe(dev, PTR_ERR(), ...) we already have
out there. Do we really want to have this variant?

>  - takes pointer, returns pointer -> ? dev_ptr_probe()

dev_ptr_probe() misses to be clear about being an error and think this is pretty
much the ERR_CAST() case right? Maybe dev_err_cast_ptr_probe()? Or
dev_err_cast_probe()?

- Nuno Sá
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 2fea2bbbe47f..e0b08283d667 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -296,11 +296,9 @@  struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name)
 	}
 
 	fwnode = fwnode_find_reference(dev_fwnode(dev), "io-backends", index);
-	if (IS_ERR(fwnode)) {
-		dev_err_probe(dev, PTR_ERR(fwnode),
-			      "Cannot get Firmware reference\n");
-		return ERR_CAST(fwnode);
-	}
+	if (IS_ERR(fwnode))
+		return dev_errp_probe(dev, PTR_ERR(fwnode),
+				      "Cannot get Firmware reference\n");
 
 	guard(mutex)(&iio_back_lock);
 	list_for_each_entry(back, &iio_back_list, entry) {