Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1077841pxb; Fri, 27 Aug 2021 00:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztcZnb5jRJ/v9SeUtz0RIh2ziS+dNYTtia4PWARVsWbVVZ7xFrt//l6GSxoeiGu40Mk4Zn X-Received: by 2002:a92:db0c:: with SMTP id b12mr5429760iln.171.1630048424818; Fri, 27 Aug 2021 00:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630048424; cv=none; d=google.com; s=arc-20160816; b=fp+zijYL8jYQEW4iiUg6/riVr928lt1pWOxNGC+1cZgIcH4OJW79cDrrm34UqxwC2e H1RJcsZpje7ffjmDJ0mucSyi/ayESeAX2S/fH5GmLprEuaKvOZST+VZgN+8UigVH6xMD ube0VBuPIdbnP0NvLnxHBiZ4LnLbV+WDeQ19o9sj1gOWgEWQuRGpCoAteSH7mSbW4Tkd mDk0CwFnP9MFklw3UJyxjhuXiWvwq7AWbVhsN/MiZALR9a+stlW0KldsZ9Wj37IKNyfk IxRxoOp45unNTgSvIbaGDWet00Tf/KrWoFlrK7whPfpsQXbbdtxFuVyeP+cBE82ZuYPI BxWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ULaok02Pp//04RR3QE7N/SGQLxFi5wtbFozDCAiKGPY=; b=FWElJfVTReXJ+rcT30VuRV4dedmRe5BV/e0jJrni9+NPGhbF8qaN359QQvyLXQgekg OWCMBBKu3pmEpBN3YndViwQbZPy38S8joXfCQ85qEV3TKAiC2ZFWYBjSxMdS5S90VqPh UAs+sD/odIFpPeRXXvmJMyHtHnjVYVrgSEHqs2lyKBxZDFxhM1ktte6N/CWTgtD7gf79 NeeBSIwWNKlfQeyr44rUKjhL1c0TNUlUVY6aYwWBTfbL9NV5LUWvSC7ejfJfZJe8p2de ad342mplbDaUomB/WKWFGrxw9y0ReNlUuqVkZRoEYzdMgSOZUPsNAEODeWBamyueDFWo du8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=By4UIGIJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 11si5300690ilq.55.2021.08.27.00.13.32; Fri, 27 Aug 2021 00:13:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=By4UIGIJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243484AbhH0HNZ (ORCPT + 99 others); Fri, 27 Aug 2021 03:13:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:57330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231739AbhH0HNW (ORCPT ); Fri, 27 Aug 2021 03:13:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86E9460F92; Fri, 27 Aug 2021 07:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630048354; bh=CNm1k9Yuyu0Cujjer61BVkr+/veDq0OstmL8jEynAHk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=By4UIGIJCwA38IiTikDWwyMoyXdkgAonVUn+0tpLQ9/rEJdTOA0VFrHIY7w6Ss9iV /h0NS/JN0AXlygYSmfJK2JeqV7rQxVP26bEXdBTJdjygeMuip62XHZKbqMAhuBuWkz zdcM7NCYztBgeRLFFuIzE88RcV0CGQrPTJ7J9Ajg= Date: Fri, 27 Aug 2021 09:12:30 +0200 From: "gregkh@linuxfoundation.org" To: Pavel Skripkin Cc: David Laight , "Larry.Finger@lwfinger.net" , "phil@philpotter.co.uk" , "straube.linux@gmail.com" , "fmdefrancesco@gmail.com" , "linux-staging@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3 5/6] staging: r8188eu: add error handling of rtw_read32 Message-ID: References: <93bf46ce2d0ce12e94672acf28b64dc341fde038.1629789580.git.paskripkin@gmail.com> <27f5e52d520b453cbcabb3d72f0f5d15@AcuMS.aculab.com> <20210826122221.5d2b0f37@gmail.com> <685618ac-8de1-4eb1-57dd-9d43b96e872e@gmail.com> <64112dfd8e8b472ab78ca8b4837dc9e9@AcuMS.aculab.com> <0eb2bbc6-9d35-9ff3-acde-fd89bbe0ca27@gmail.com> <6e864f9d133d4db3923190f5acacc32a@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021 at 11:03:04PM +0300, Pavel Skripkin wrote: > On 8/26/21 1:59 PM, David Laight wrote: > > From: Pavel Skripkin > > > Sent: 26 August 2021 11:55 > > > > > > On 8/26/21 1:22 PM, David Laight wrote: > > > > From: Pavel Skripkin > > > >> Sent: 26 August 2021 10:28 > > > >> > > > >> On 8/26/21 12:22 PM, Pavel Skripkin wrote: > > > >> > On Thu, 26 Aug 2021 08:51:23 +0000 > > > >> > David Laight wrote: > > > > ... > > > >> >> ... > > > >> >> > -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 > > > >> > > > > >> Oops, I thought about BUG_ON() instead of WARN_ON(), sorry for > > > >> confusion. My point is "we should not let the box boom". > > > > > > > > > > > > There is no point checking for NULL that just can't happen. > > > > In this case all the callers will pass the address of a local. > > > > There really is no point checking. > > > > > > > > > > We not always read in local variable, there are few places, where we > > > read into passed buffer. > > > > It is still a very local coding bug. > > > > David > > > > Sure, but is defensive programming so bad? Yes it is, for when it is not needed. > Greg, what your opinion about this NULL check? Never check for things that you know are not going to happen. Otherwise the kernel would just be full of pointless checks everywhere. And why are you waiting for me to tell you this? Why do you not believe David? thanks, greg k-h