Re: [PATCH v3 5/6] staging: r8188eu: add error handling of rtw_read32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 26 Aug 2021 08:51:23 +0000
David Laight <David.Laight@xxxxxxxxxx> wrote:

> From: Pavel Skripkin <paskripkin@xxxxxxxxx>
> > Sent: 24 August 2021 08:28
> > 
> > _rtw_read32 function can fail in case of usb transfer failure. But
> > previous function prototype wasn't designed to return an error to
> > caller. It can cause a lot uninit value bugs all across the driver
> > code, since rtw_read32() returns local stack variable to caller.
> > 
> > Fix it by changing the prototype of this function. Now it returns an
> > int: 0 on success, negative error value on failure and callers
> > should pass the pointer to storage location for register value.
> 
> Pretty horrid API interface.
> Functions like readl() - which can fail just return ~0u and let
> the caller worry about whether that causes serious grief.
> 
> You could make all the read functions return __u64 and return ~0ull
> on error.
> Testing for (value & 1ull << 63) will be reasonable even on 32bit.
> 

I am not the best at API related questions, so can you, please,
explain why your approach is better? 

As I can see, most of the drivers in usb/ directory use smth like this
interface for private reading funcions. We anyway creating tmp variable
(but 64 bit _always_) and checking for mistery error, which we cannot
pass up to callers.

Sorry, if it's _too_ dumb question, but I really can't get your
point....



 

> ...
> > -static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
> > +static int usb_read32(struct intf_hdl *pintfhdl, u32 addr, u32
> > *data) {
> >  	u8 requesttype;
> >  	u16 wvalue;
> >  	u16 len;
> > -	__le32 data;
> > +	int res;
> > +	__le32 tmp;
> > +
> > +	if (WARN_ON(unlikely(!data)))
> > +		return -EINVAL;
> > 
> 
> Kill the NULL check - it is a silly coding error.
> An OOPS is just as easy to debug.
> 


I don't think that one single driver should kill the whole system. It's
100% an error, but kernel can recover from it (for example disconnect
the driver, since it's broken).


AFIAK, Greg and Linus do not like BUG_ONs in recoverable state...
Correct me, if I am wrong




With regards,
Pavel Skripkin






[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux