Received: by 10.192.165.156 with SMTP id m28csp350114imm; Mon, 16 Apr 2018 00:50:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx49zufvJkzjagZfBliwQJnhD9RLSVSkQEw9BaFDGenjMyjH92+9skHs/wIuL+6OMCmFxjuIE X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr3426847plc.87.1523865038672; Mon, 16 Apr 2018 00:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523865038; cv=none; d=google.com; s=arc-20160816; b=XJ5MfM2ckvgwEHkvD0E2FXiJL86AsPsLUdyi4ygj5+H7x1z43xfPCQT/AuikWmEIkn 5fyWkFAxVQelIhfQzgpkPhFT7l2aSR5I0DjnUZ+uBVq8/vuDZmSI11xAiFZEVFWXLCzJ 7LgQ0/PrkVH1HuLb4kxsJ5OEHQVf/hEGMn9NeKYm1jIfQSAX/x9qRzLQFLZgrjCnHtpp ZWsyLuRuySit3n2s5vTr2nz5wKQdp97ZGwLBf6Y+UdAerXwsWuqp3n074giJ7mr4tQ1N GuxFZEV5YTrbReALDktan4a3P4dJ9Gfsk31Rfa9kDRweNWMpRbzkKV0tirIPISKfvjBB V8Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Jq7budYlHMrC1zqkqdNT198JLpCy7DLgHRhWfYZD30A=; b=qxxGN4ZXhKsqimATTjROHU/5t6Dw9NQyKjAFJogpGQ+m47Uk/fgsKLPyFc46U48FVy dDBKSyUZ+xdB3dxfHGJI9PIkHwETn9WY7FyWUsSSf46qwz1Pbg4kMQyr5HW/4EjvCt7Q llnqRC1FWOoH61yN1FWVUdSSRESH9+8eFUM6+EFTVlN+441sAK+947o5D3ZN6WTVec3y 3iziZAtypFvkV02KbbeSBqIjfOmKb9lON4iN3R3eCgOGPu5DRShAKfr6O49cY4zrAx2L m1cx3LllPnqn+d3omu/9kMgaB7yUw1w/m/graVDd3tpuoAYrYPRBps9rrqXgF6w0PG8t iq/Q== 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 b17si627873pgs.110.2018.04.16.00.50.24; Mon, 16 Apr 2018 00:50:38 -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 S1753412AbeDPHtI (ORCPT + 99 others); Mon, 16 Apr 2018 03:49:08 -0400 Received: from mout.gmx.net ([212.227.17.21]:44045 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753299AbeDPHtG (ORCPT ); Mon, 16 Apr 2018 03:49:06 -0400 Received: from localhost.localdomain ([122.225.81.134]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MMYZG-1f5DjQ1zsU-008MlT; Mon, 16 Apr 2018 09:48:51 +0200 From: Chengguang Xu To: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chengguang Xu Subject: [PATCH 2/2] fs/9p: detecting invalid options as much as possible Date: Mon, 16 Apr 2018 15:48:29 +0800 Message-Id: <1523864909-4337-2-git-send-email-cgxu519@gmx.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1523864909-4337-1-git-send-email-cgxu519@gmx.com> References: <1523864909-4337-1-git-send-email-cgxu519@gmx.com> X-Provags-ID: V03:K1:4E3qBia6Z85szOg6SZU1D63mSQ93nEgy5h6qrUzgr0kACBajSie UliZZOpUHDLImAPh/wYr4KiA180FQeS+ygXWfd6sajxZ+Bn75QfIccwjX7wfzVPAyJwJ3CX wzX0aR685e1RtWekFXIA5pjTjktiMvFmV0NHtfx5Vt9SaLP/4jHVlAEzbqGJqOU0tgqYWtc V4YOzbb44XarmT8xIihoQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:k/wUnz9Se1s=:um2uhtqJPA0egRhBsEvhqp 5caA02hwF5Ph63u+HnOp64dvN0G2WcUF7CfGAoQjurtbkti/ZQLHit8OE/nI9rEVONuLw3IDH jVQfiXTNpclultKh8ezKdhYhIJCMtkI2sNgTHNiknonjtuNuNj+rhMGcMroG+tt1aQSq9e82r AuXVzoo9uhDxWJUX5Mof81MZbovcyZMCtqfahIQ7IRVeU+IoxlxuoKs7cDaF/ki/Ko3rCExFe WXfeD6mSGKuSao4WnvkXrBbl70ADBbpz9DIqsrCGMsZxJ1gizrR59B5LzyzJRO+VJbduuorTz m3CAhlzw9R58CgN5INrBeyXJi2arDldlqIiwEKL29TecUJCdazFhs/411VXF1j2gUQbs77ahe XoqrTKYXMbbyMrzTrTecJnnOE07Gsk6mr0t33K0nyBzP6HBqyIxFRaJygmjfScdfZYsgjc3ek CbDF0nP8f1RMuA+qXVqxwdKu85X8eoL5Mq3gdfFxzWDunfbm/Eo41cUaKybI0Tu/Rl1qHEUUv K2hqKC394N+1WVwJfMsXWdZxhMKYEkXmq0soHJNVVW+otqds4rNQ8accKNpPfc4ATvLtu7a7z qi82tRK0/7gi+eLyNpZOohSalbc36moRugkq1CpjmPYVwlcNHkoSYUOdiYRZJi0WmqFKZors8 bPjv89dhOBHMy+FDEXjpsJ1A4UTWTOBMTADMcEPauLUEQw7acC5X6z1PLwDUy1tlXO0p+E2AY kxs4Iexi/04U3bZcnC/PyysQcXKBgezUgBiUz3CkSXEYu7cZm9fiJjgYvet6cwSrqFKoQJmrr 89B6tYdL80jS4TOcYzKPv4xko2DbA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently when detecting invalid options in option parsing, some options(e.g. debug) just set errno and allow to continusly validate other options so that it can detect invalid options as much as possible and give proper error messages together. This patch apply this policy to all options and the case of memory allocation error in option parsing. Signed-off-by: Chengguang Xu --- fs/9p/v9fs.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index e622f0f..29ba937 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -192,10 +192,9 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) return 0; tmp_options = kstrdup(opts, GFP_KERNEL); - if (!tmp_options) { - ret = -ENOMEM; - goto fail_option_alloc; - } + if (!tmp_options) + return -ENOMEM; + options = tmp_options; while ((p = strsep(&options, ",")) != NULL) { @@ -263,18 +262,16 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) case Opt_uname: kfree(v9ses->uname); v9ses->uname = match_strdup(&args[0]); - if (!v9ses->uname) { - ret = -ENOMEM; - goto free_and_return; - } + if (!v9ses->uname) + if (!ret) + ret = -ENOMEM; break; case Opt_remotename: kfree(v9ses->aname); v9ses->aname = match_strdup(&args[0]); - if (!v9ses->aname) { - ret = -ENOMEM; - goto free_and_return; - } + if (!v9ses->aname) + if (!ret) + ret = -ENOMEM; break; case Opt_nodevmap: v9ses->nodev = 1; @@ -292,24 +289,24 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) #ifdef CONFIG_9P_FSCACHE kfree(v9ses->cachetag); v9ses->cachetag = match_strdup(&args[0]); - if (!v9ses->cachetag) { - ret = -ENOMEM; - goto free_and_return; - } + if (!v9ses->cachetag) + if (!ret) + ret = -ENOMEM; #endif break; case Opt_cache: s = match_strdup(&args[0]); if (!s) { - ret = -ENOMEM; + if (!ret) + ret = -ENOMEM; p9_debug(P9_DEBUG_ERROR, "problem allocating copy of cache arg\n"); - goto free_and_return; + continue; } ret = get_cache_mode(s); if (ret == -EINVAL) { kfree(s); - goto free_and_return; + continue; } v9ses->cache = ret; @@ -319,10 +316,11 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) case Opt_access: s = match_strdup(&args[0]); if (!s) { - ret = -ENOMEM; + if (!ret) + ret = -ENOMEM; p9_debug(P9_DEBUG_ERROR, "problem allocating copy of access arg\n"); - goto free_and_return; + continue; } v9ses->flags &= ~V9FS_ACCESS_MASK; @@ -341,14 +339,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) pr_info("Unknown access argument %s\n", s); kfree(s); - goto free_and_return; + continue; } v9ses->uid = make_kuid(current_user_ns(), uid); if (!uid_valid(v9ses->uid)) { ret = -EINVAL; pr_info("Uknown uid %s\n", s); kfree(s); - goto free_and_return; + continue; } } @@ -365,13 +363,14 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts) break; default: + p9_debug(P9_DEBUG_ERROR, + "unrecognized mount option \"%s\" or missing value\n", + p); continue; } } -free_and_return: kfree(tmp_options); -fail_option_alloc: return ret; } -- 1.8.3.1