Re: [PATCH] usb: rtl8150: avoid using uninitialized CSCR value

Michal Pecio
2026-04-08T08:33:49Z

On Mon, 6 Apr 2026 01:38:06 +0200, Andrew Lunn wrote:
> > > - get_registers(dev, CSCR, 2, &tmp);
> > > + if (get_registers(dev, CSCR, 2, &tmp) < 0)
> > > + tmp = 0;
> > > if (tmp & CSCR_LINK_STATUS)
> > > netif_carrier_on(netdev);
> > > else
> >
> > I was wondering if calling netif_carrier_off() is the right thing
> > to do in case get_registers() fail.
> >
> > There are multiple get_registers() calls that don't check the error
> > and if we do this in set_carrier() maybe we should do the same
> > thing across the whole driver?
>
> What does it actually mean if get_registers() fails? The device is
> gone? Hot unplugged? If so, you are going to get a cascade of errors,
> and then hopefully the USB core code removes the device?
>
> Are there any legitimate reasons for get_registers() to fail if the
> device is still plugged in?

In principle it might be temporary EMI or a flaky cable. These errors
rarely reach drivers due to retries in USB layer, but in extreme cases
the device may be in unknown state and it may become functional later.
IIRC net layer has some operations which are presumed trivial enough
that they would never fail, so this could be annoying.

It does seem rare enough in practice that for 25 years nobody noticed
carrier status being set to a random vaule by this driver.

BTW, some functions like rtl8150_reset() pre-set data to a value which
will be safe in case of get_register() failure. But here, unhandled
set_register() error is dodgy - the 0x10 bit may never turn on.

Regards,
Michal