[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <27f5e52d520b453cbcabb3d72f0f5d15@AcuMS.aculab.com>
Date: Thu, 26 Aug 2021 08:51:23 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Pavel Skripkin' <paskripkin@...il.com>,
"Larry.Finger@...inger.net" <Larry.Finger@...inger.net>,
"phil@...lpotter.co.uk" <phil@...lpotter.co.uk>,
"gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
"straube.linux@...il.com" <straube.linux@...il.com>,
"fmdefrancesco@...il.com" <fmdefrancesco@...il.com>
CC: "linux-staging@...ts.linux.dev" <linux-staging@...ts.linux.dev>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v3 5/6] staging: r8188eu: add error handling of rtw_read32
From: Pavel Skripkin <paskripkin@...il.com>
> 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.
...
> -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.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists