Re: [PATCH 1/2] sh: kfr2r09: fix i2c adapter leak on USB gdaget setup
From: Johan Hovold
Date: Thu Jun 25 2026 - 02:45:34 EST
Hi Geert,
On Wed, Jun 24, 2026 at 10:29:41AM +0200, Geert Uytterhoeven wrote:
> On Fri, 8 May 2026 at 14:06, Johan Hovold <johan@xxxxxxxxxx> wrote:
> > Make sure to drop the reference taken to the I2C adapter (and its
> > module) when enabling USB gadget mode which prevents the adapter from
> > ever being deregistered.
> >
> > Fixes: 5a1c4cb5bc22 ("sh: add r8a66597 usb0 gadget to the kfr2r09 board")
> > Cc: stable@xxxxxxxxxxxxxxx # 2.6.32
> > Cc: Magnus Damm <damm@xxxxxxxxxx>
> > Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
> > @@ -387,9 +387,16 @@ static int kfr2r09_usb0_gadget_i2c_setup(void)
> > msg.flags = 0;
> > ret = i2c_transfer(a, &msg, 1);
> > if (ret != 1)
> > - return -ENODEV;
> > + goto err_put_adapter;
> > +
> > + i2c_put_adapter(a);
> >
> > return 0;
> > +
> > +err_put_adapter:
> > + i2c_put_adapter(a);
> > +
> > + return -ENODEV;
>
> I case i2c_transfer() returns a negative error code (the other
> possible value is zero, right?), you might want to propagate that to
> the caller. However, the single caller replaces it by -ENODEV anyway,
> so I guess your patch is fine.
Yes, indeed, but that's arguably a separate change. And in this case it
doesn't really matter currently as you point out.
> Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
Thanks for reviewing.
Johan