diff mbox series

[v4,1/9] i2c: riic: Introduce a separate variable for IRQ

Message ID 20250103091900.428729-2-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State Under Review
Delegated to: Geert Uytterhoeven
Headers show
Series i2c: riic: driver cleanup and improvements | expand

Commit Message

Lad, Prabhakar Jan. 3, 2025, 9:18 a.m. UTC
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Refactor the IRQ handling in riic_i2c_probe by introducing a local variable
`irq` to store IRQ numbers instead of assigning them to `ret`. This change
improves code readability and clarity.

Remove explicit error handling after `platform_get_irq()` since
`devm_request_irq()` already handles such errors.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
v3->v4
- New patch
---
 drivers/i2c/busses/i2c-riic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Geert Uytterhoeven Jan. 3, 2025, 10:47 a.m. UTC | #1
Hi Prabhakar,

Thanks for your patch!

On Fri, Jan 3, 2025 at 10:19 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Refactor the IRQ handling in riic_i2c_probe by introducing a local variable
> `irq` to store IRQ numbers instead of assigning them to `ret`. This change
> improves code readability and clarity.
>
> Remove explicit error handling after `platform_get_irq()` since
> `devm_request_irq()` already handles such errors.

Where does it handle such errors?
I only found the following check in request_threaded_irq():

        desc = irq_to_desc(irq);
        if (!desc)
                return -EINVAL;

Although irq_to_desc() takes an unsigned int, it should indeed catch
invalid (negative) interrupt numbers, but the code above would not
propagate the correct error code (e.g. -EPROBE_DEFER).

> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>


> --- a/drivers/i2c/busses/i2c-riic.c
> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -464,11 +464,9 @@ static int riic_i2c_probe(struct platform_device *pdev)
>                 return ret;
>
>         for (i = 0; i < ARRAY_SIZE(riic_irqs); i++) {
> -               ret = platform_get_irq(pdev, riic_irqs[i].res_num);
> -               if (ret < 0)
> -                       return ret;
> +               int irq = platform_get_irq(pdev, riic_irqs[i].res_num);

So I think you need to keep a check for irq < 0.

>
> -               ret = devm_request_irq(dev, ret, riic_irqs[i].isr,
> +               ret = devm_request_irq(dev, irq, riic_irqs[i].isr,
>                                        0, riic_irqs[i].name, riic);
>                 if (ret) {
>                         dev_err(dev, "failed to request irq %s\n", riic_irqs[i].name);

Gr{oetje,eeting}s,

                        Geert
Lad, Prabhakar Jan. 3, 2025, 12:21 p.m. UTC | #2
Hi Geert,

Thank you for the review.

On Fri, Jan 3, 2025 at 10:48 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> Thanks for your patch!
>
> On Fri, Jan 3, 2025 at 10:19 AM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> >
> > Refactor the IRQ handling in riic_i2c_probe by introducing a local variable
> > `irq` to store IRQ numbers instead of assigning them to `ret`. This change
> > improves code readability and clarity.
> >
> > Remove explicit error handling after `platform_get_irq()` since
> > `devm_request_irq()` already handles such errors.
>
> Where does it handle such errors?
> I only found the following check in request_threaded_irq():
>
>         desc = irq_to_desc(irq);
>         if (!desc)
>                 return -EINVAL;
>
> Although irq_to_desc() takes an unsigned int, it should indeed catch
> invalid (negative) interrupt numbers, but the code above would not
> propagate the correct error code (e.g. -EPROBE_DEFER).
>
Agreed, I had missed that. I will restore the check.

Cheers,
Prabhakar
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index 9264adc97ca9..c9b2ceaf4000 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -464,11 +464,9 @@  static int riic_i2c_probe(struct platform_device *pdev)
 		return ret;
 
 	for (i = 0; i < ARRAY_SIZE(riic_irqs); i++) {
-		ret = platform_get_irq(pdev, riic_irqs[i].res_num);
-		if (ret < 0)
-			return ret;
+		int irq = platform_get_irq(pdev, riic_irqs[i].res_num);
 
-		ret = devm_request_irq(dev, ret, riic_irqs[i].isr,
+		ret = devm_request_irq(dev, irq, riic_irqs[i].isr,
 				       0, riic_irqs[i].name, riic);
 		if (ret) {
 			dev_err(dev, "failed to request irq %s\n", riic_irqs[i].name);