Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp257500pxb; Thu, 26 Aug 2021 02:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/gRj4X4bc05yKSi9+cfj+FhQZLTkODNMLNsbUaMfXx7tN19qf+fzckmjiOfFo7qjCc1oj X-Received: by 2002:a5d:8758:: with SMTP id k24mr2216976iol.128.1629969880295; Thu, 26 Aug 2021 02:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629969880; cv=none; d=google.com; s=arc-20160816; b=tFjMw9+TXmpUQd+DQ6ln+qsnze3PHLAB/Ofyv3SyKZsJ0mipBjZdOfyFiKwhtHucbr dzp1gE0El0Wiew+oNs7FUpKn2/rc1F2MBCeb5yaiu+hJc+giCytMzSaJx1vtk/9zPpKJ pQd9F1hpcgNzM8noQsXymEoI52ezQ9vPOREhDimZpqU54PBAcYVmqLhNf3QJgjOsXANy gycs8pfl2krSmET9Z8559gIm4IB0nosFDUSvHaREVtHvkWlbEvqmweLtCDnDp2wOdcJ+ 7i7nQREdXCCmZeWbb0Y6ohtKZq26iM4esZTYe0er9qbC4ikDyWlV9kdBH3tjD1zPqRv3 /JFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6K808PPjkpTkbnbXiY0eI5Jv3rPmmxFhKf+SD20t3Yw=; b=zkLMwbqt1GhnOjrADk7ckfndNsaL0fD3Edvb2f0S6BcYvlgnxfwtP8IpeUsn0Bw0lQ U7X/aBKYEkr67vZtYni6dJVC9vy6lZUGpw9BXK5+LL7DQsWnDVzvRpyqsNRDYqg45m4H ZYePBdpYRmE3eXpdpBGIB4CRNhRtVlE+6ZvXStw35V5IiuORf/DzV8h7clQ05V9r7Eje 4RfMBX9hvm4ZWZ4zqCRrqmKdye1RKSH172VIACJ2b8F8OoHp5brsyC2JYMJI5mCl6bx4 DGg+uS4yKcXjJHxkt3Eff77r7vYMVsz4zCScnkYCgg0zhItVjNewjTL6h/buplth4Q4P 2spw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="jNbx/CXF"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si2450485ios.62.2021.08.26.02.24.28; Thu, 26 Aug 2021 02:24:40 -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=@gmail.com header.s=20161025 header.b="jNbx/CXF"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240861AbhHZJXa (ORCPT + 99 others); Thu, 26 Aug 2021 05:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbhHZJX3 (ORCPT ); Thu, 26 Aug 2021 05:23:29 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B9DC061757 for ; Thu, 26 Aug 2021 02:22:42 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id l18so3859242lji.12 for ; Thu, 26 Aug 2021 02:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6K808PPjkpTkbnbXiY0eI5Jv3rPmmxFhKf+SD20t3Yw=; b=jNbx/CXFJ1awFZl7w0ExP7cey9tcu5AznJzGiOYNNLAK43p44dAebQ6A0vjlReUkjO TNI1IqL3rSa+b0Vir7td6Footj1xXylICv/fmelssTYfz4QASNDahohRy1iuD8CYmIx5 +6TWawSxNC4Gdr8N7HOuUESpr9BKnjZaBBqBhscH0VPL92CFF2avXpLDmuMBSCXw112G 7VXxkEk8+aWh8crWn13n2MYo8sdTtQdwL5uz/qqwiHrwir53wFCaL/rESzCPe6LVnjnM yLmzwWlqORX81g7KqbuuK6eYRVlsCqGKlwUO1oAWW8ubr2Smpn/NOPfr1jm8FkSP2qsr FTDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6K808PPjkpTkbnbXiY0eI5Jv3rPmmxFhKf+SD20t3Yw=; b=YxDAXiXIC6rpK2rqBjRK+RS8KLvaheI+I+0IbV6OoB8BVBkG9zKrf6N7IcsIhpQgxM TAsg4KeubwGnUByJyvHNqiLN9nDtfxMkQKR3qVro38z6bjBABVIDRMm7A/8ofX6uKo58 1hMGQWmnWwM81TTZROzxBrWWbg36Ho0TM2X0cKyrPAkZw0FwH8x7rYhpEukClmvvID2d dOuwr4RgftFB6lNL8eh+0sa0UMQRL50veOTIgGzxTwtzkH7hCsPZuvdZUtiV78o4dg5X 9FVCUYfsyXTRnevuTiiwUskvZy82ysQTB5B8Veiedoc1Pwgicxo/WSuqKuNcdeJpA6Yt k7GA== X-Gm-Message-State: AOAM533Ft7phZ2jxQF8lYmeQeOkJi4IQnNoeRQU6XPyZZT+Dba8ABRT9 B/eGWmmZb/XCZdC5Xq7XCWOTIxRzgaucvg== X-Received: by 2002:a2e:a88a:: with SMTP id m10mr2197733ljq.440.1629969760985; Thu, 26 Aug 2021 02:22:40 -0700 (PDT) Received: from localhost.localdomain ([46.61.204.60]) by smtp.gmail.com with ESMTPSA id z13sm285020ljo.37.2021.08.26.02.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 02:22:40 -0700 (PDT) Date: Thu, 26 Aug 2021 12:22:21 +0300 From: Pavel Skripkin To: David Laight Cc: "Larry.Finger@lwfinger.net" , "phil@philpotter.co.uk" , "gregkh@linuxfoundation.org" , "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: <20210826122221.5d2b0f37@gmail.com> In-Reply-To: <27f5e52d520b453cbcabb3d72f0f5d15@AcuMS.aculab.com> References: <93bf46ce2d0ce12e94672acf28b64dc341fde038.1629789580.git.paskripkin@gmail.com> <27f5e52d520b453cbcabb3d72f0f5d15@AcuMS.aculab.com> X-Mailer: Claws Mail 3.17.8git77 (GTK+ 2.24.33; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Aug 2021 08:51:23 +0000 David Laight wrote: > From: Pavel Skripkin > > 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