Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1547760pxb; Fri, 6 Nov 2020 12:34:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwT5sdYmIgglv38U3v7N+bqFOs40HCLhQD85BZhCPmQCSqFNuRLFvIgQKkdQ+UILPgcNLeo X-Received: by 2002:a50:e705:: with SMTP id a5mr3939010edn.29.1604694867186; Fri, 06 Nov 2020 12:34:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604694867; cv=none; d=google.com; s=arc-20160816; b=AaisGO/wDmlJnCQ6WK1E/qRjVWgZZaGFzS0nAYvz/bqt1ruMkHb9OAX8HKDwUzwg6q 8o6JCZZEPe6/H0kFlVzJPs0YujlnRr0ZB2F/WPfIfuMBsxSjrgichYpAcRo9S4CYuQbr pWMLPwaU9gZxX0i7oRDrq8UDheINLQm2BQB27wPAo4uT1cWZoGF5SL357wjr9uqD8pZu u5qYvSmrK2IPDaj/xfKI1BvluJ5M3iss3Jr54ChymDOX8YaegkEKgJdsBKQHKK404seo AuAgZFgkJn7OouuI7u470KoXER0Ygx/KIt7SqDA67vzDfF19wX7A6B9iyYnGHW3OKlnS NLQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=jl/TfawUOLh46iaNG5SsHe8oJVEJ3Gkb+6VXRnAvN74=; b=t+w9QufDRSmpKAm3tugcHHkTnUeDda5klVsyAvLZyvC/4vq5uHaVwbODi27gUoQOIm b9pzo/UG1KMt1VRvAqxfM5wUJ8WgWh4/znrcUuS6JeDKOnutVxKz/0Sq9lk74k+qbHds qZDOupKt87RYRpYwNVMUyhlJ9ii3oSn/AeU6vTQIBICO2uuTVkWbFQKTqtfMhpqveCCv jvp3Z68ZQKsXPLfZPgohtODTrn4rSdlqBde7dpXzVuJiEzxaoZR/6sx5i4XTGdwAzT9C bFN1RSwAKG6GJpAU4LNwbnoa6w1GjmeIU/W7SQjE4KUW9EPG7OTWC+ouNFIvTojZCGZZ xYUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=JgA7Y04B; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si1844494ede.591.2020.11.06.12.33.53; Fri, 06 Nov 2020 12:34:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-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=@fieldses.org header.s=default header.b=JgA7Y04B; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728434AbgKFUdS (ORCPT + 99 others); Fri, 6 Nov 2020 15:33:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728408AbgKFUdR (ORCPT ); Fri, 6 Nov 2020 15:33:17 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D07EDC0613CF for ; Fri, 6 Nov 2020 12:33:17 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id CED29BD2; Fri, 6 Nov 2020 15:33:16 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org CED29BD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1604694796; bh=jl/TfawUOLh46iaNG5SsHe8oJVEJ3Gkb+6VXRnAvN74=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JgA7Y04BUs8FTi+1LbfDEl5K6z8eyAqBVetcX1JXhEEbl7s3bLiBhCqf5P8B2IAEt w07WFfnzbKqIjL0tDISYl1XBjcDAYcjlbkwxzMCfCiPlvslRncVsAop+SesR3a98IW jNIzGVlObjB2wNswtPhpmRWdnkpDsOQfBVB92h7A= Date: Fri, 6 Nov 2020 15:33:16 -0500 From: "J. Bruce Fields" To: Dan Carpenter Cc: Trond Myklebust , Artur Molchanov , Anna Schumaker , Chuck Lever , Jakub Kicinski , linux-nfs@vger.kernel.org, kernel-janitors@vger.kernel.org, Colin King Subject: Re: [PATCH] net/sunrpc: clean up error checking in proc_do_xprt() Message-ID: <20201106203316.GA26028@fieldses.org> References: <031F93AC-744F-4E02-9948-1C1F5939714B@gmail.com> <20201027141758.GA3488087@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201027141758.GA3488087@mwanda> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, Oct 27, 2020 at 05:17:58PM +0300, Dan Carpenter wrote: > There are three changes but none of them should affect run time: > > 1) You can't write to this file because the permissions are 0444. But > it sort of looked like you could do a write and it would result in > a read. Then it looked like proc_sys_call_handler() just ignored > it. Which is confusing. It's more clear if the "write" just > returns zero. > 2) The "lenp" pointer is never NULL so that check can be removed. > 3) In the original code, the "if (*lenp < 0)" check didn't work because > "*lenp" is unsigned. Fortunately, the memory_read_from_buffer() > call will never fail in this context so it doesn't affect runtime. > > Signed-off-by: Dan Carpenter > --- > net/sunrpc/sysctl.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/net/sunrpc/sysctl.c b/net/sunrpc/sysctl.c > index a18b36b5422d..04526bab4a06 100644 > --- a/net/sunrpc/sysctl.c > +++ b/net/sunrpc/sysctl.c > @@ -63,19 +63,19 @@ static int proc_do_xprt(struct ctl_table *table, int write, > void *buffer, size_t *lenp, loff_t *ppos) > { > char tmpbuf[256]; > - size_t len; > + ssize_t len; > > - if ((*ppos && !write) || !*lenp) { > - *lenp = 0; > + *lenp = 0; > + > + if (write || *ppos) > return 0; > - } > + > len = svc_print_xprts(tmpbuf, sizeof(tmpbuf)); > - *lenp = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); > + len = memory_read_from_buffer(buffer, *lenp, ppos, tmpbuf, len); Except now we're passing *lenp = 0, that can't be right. Though I actually kind of prefer this to Colin King's patch which just casts (*lenp) in the comparison below. --b. > + if (len < 0) > + return len; > > - if (*lenp < 0) { > - *lenp = 0; > - return -EINVAL; > - } > + *lenp = len; > return 0; > } > > -- > 2.28.0