Received: by 10.192.165.148 with SMTP id m20csp1165557imm; Wed, 2 May 2018 15:33:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq6wj6yHtkcEQDM+UYy967qZtwZpiAZ6e+z3Jyd4tJvjESbWdeuBoP1Tz9Mra4pU5GDQ6fp X-Received: by 10.98.24.214 with SMTP id 205mr20990451pfy.242.1525300411282; Wed, 02 May 2018 15:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525300411; cv=none; d=google.com; s=arc-20160816; b=fXWdYet+V0HRr75ooqjnoO7ZfQtb2weoZ2jgq9n6P6l09Pyd6NpbxcXSOSuwwq7Zef QmjVKoD79y8ddSA4R8QMf0ns32OUbOI6sieofBEQwOpFN2RSCVjdmQbo77XHykqFABXy /8gWnbqJYtYZGteWP+7KYic9YUPLd5ixufGuomK2zV09FlUHZN+GxAiRQa0tfHUHAQdx 1t7VndLvaeY/MxWwApV96TxZYQD4qqESyORhrsa2JzR4zvcp+oVHuXUhVXXsnKnHIJw9 nK/2uwSliDBMphgBDJ58nEbtpjGrvbUqHq/mclvt6MTA+IJLegqIMU6K+ghFj2yRYeCT DMZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=T9wlImYkqxs9eXjDkWJXg8XbyiesBNWVCmSJj8ysTyE=; b=N4lVbet/oj0A2RKmLQxp6zTuDy3hs9JNAnbWbRP2o08lwEinAMOInnDYeTjN/yCW4W /qGbIn6pSW0pER/0yQuq06Oif3/aqZ1qTl9MCucfEaWHpxcMpqNPPqRO601omZH1Gi/G Cpifw4P45/Xw5iYJxCEe59IVe8/KlePxPg4gsWN5I7dSGx86tQTeNmNsus7O11zb+ob6 /hTXFwdprgdXSo/0zrla3IbLm+0w7cBvdHlW2tsb6pfayRf09plNQajNEuIIRBWHnYHf IlJhvG03JkVIHeLbLfdfSiIF2mgjlLmwhfBic512g15b5l/lMN/Ub1qHoreipUlRurpu TFAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y9-v6si7333630pgc.601.2018.05.02.15.33.16; Wed, 02 May 2018 15:33:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751771AbeEBWdF (ORCPT + 99 others); Wed, 2 May 2018 18:33:05 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50892 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751688AbeEBWdA (ORCPT ); Wed, 2 May 2018 18:33:00 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EECE86C; Wed, 2 May 2018 22:32:59 +0000 (UTC) Date: Wed, 2 May 2018 15:32:58 -0700 From: Andrew Morton To: Chengguang Xu Cc: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net, v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [V9fs-developer] [PATCH v2 1/2] net/9p: detecting invalid options as much as possible Message-Id: <20180502153258.39b65209a0a85063441c6d85@linux-foundation.org> In-Reply-To: <1523947502-6103-1-git-send-email-cgxu519@gmx.com> References: <1523947502-6103-1-git-send-email-cgxu519@gmx.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 17 Apr 2018 14:45:01 +0800 Chengguang Xu wrote: > Currently when detecting invalid options in option parsing, > some options(e.g. msize) just set errno and allow to continuously > validate other options so that it can detect invalid options > as much as possible and give proper error messages together. > > This patch applies same rule to option 'trans' and 'version' > when detecting EINVAL. > > ... A few issues: > --- a/net/9p/client.c > +++ b/net/9p/client.c > @@ -199,7 +199,7 @@ static int parse_opts(char *opts, struct p9_client *clnt) > s); > ret = -EINVAL; > kfree(s); > - goto free_and_return; > + continue; > } > kfree(s); > break; Here we can just do --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix +++ a/net/9p/client.c @@ -198,8 +198,6 @@ static int parse_opts(char *opts, struct pr_info("Could not find request transport: %s\n", s); ret = -EINVAL; - kfree(s); - continue; } kfree(s); break; > @@ -217,7 +217,7 @@ static int parse_opts(char *opts, struct p9_client *clnt) > ret = get_protocol_version(s); And here's the patch introduces a bug: if `ret' has value -EINVAL from an earlier parsing error, this code will overwrite that error code with zero. So you'll need to introduce a new temporary variable here. And I suggest that for future-safety, we permit all error returns from get_protocol_version(), not just -EINVAL. So something like: --- a/net/9p/client.c~net-9p-detecting-invalid-options-as-much-as-possible-fix +++ a/net/9p/client.c @@ -214,13 +214,12 @@ static int parse_opts(char *opts, struct "problem allocating copy of version arg\n"); goto free_and_return; } - ret = get_protocol_version(s); - if (ret == -EINVAL) { - kfree(s); - continue; - } + pv = get_protocol_version(s); + if (pv >= 0) + clnt->proto_version = pv; + else + ret = pv; kfree(s); - clnt->proto_version = ret; break; default: continue; _ Similar changes can be made to patch 2/2.