Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5841415imm; Tue, 12 Jun 2018 14:23:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJqCUzZj/abITdSXeCDTQ8wnDscPx3HnQKmobE65e9mC58g06C9BYFo27Y+2Dsd/iAVwJqn X-Received: by 2002:a17:902:d68b:: with SMTP id v11-v6mr2153637ply.16.1528838602741; Tue, 12 Jun 2018 14:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528838602; cv=none; d=google.com; s=arc-20160816; b=OEDV2VuXVueh+d6krqW1Ndnj06uXZjAv8eRgQ1QidieH19n+IFbt3ybV6ksWGXkpJd BOKflol7ySeh6sL9VcWzROOc0yJ5pKWdo4PXk+p+KZH71jXRoOO/3KgzdEU29jWhUo6T omvJMeJnBeStrHLG930vNWmlYegnftXGNWR15260rp1nCi0zN4cYDd86RMmv9D15OrcA uKFHs/fsfqsoZ2VbvDI4YtbAVhuyJKuhtIyXBNnOlgCQp8+LcQxoyktFt4HQ3k/H0ws6 zLDIWlORnO1mAjizIHOGcOzCadRtSK5enH/qNGFr1GsO1xr8Pn5HW6OzlW5emJwD1VKU WfFg== 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:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=Dsix5+yLN10un2BUY1yx9TOdoSH+S/QV4iXLVIjoGSw=; b=ZhTWfgbR09xr+umqtztzxKBdTPgWwcffn3r9A2HV2pcDF51jL04dJH9+tcmX8IC6c5 tjC6eJWW/h7NTQQqq4Ovot8LN9UMMRv+Mvg7wiB6T8FIIFmA23B2lAeY/SEJ8MEeesYs 0MuRcwh0VbbDoPw1OZ2ontQMI2iSLE2U2x8mqq1mTC/rTmcdQxeQ17gjeHdesfgR/EJ1 FvlNUYssEkHP7rYifXBno3FgN1u9iKRtmLTN95/DTbGpd6LB1g/pesWTi8FF5lTyBTIQ O5btyiSxzEz5ZfP00MWajkEEu+6i7SzAhpaNGbzUggpj9MsU2sF8Ju0csNMtw0o/GMyv ArQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=IfI56sYj; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si1019289plt.258.2018.06.12.14.23.08; Tue, 12 Jun 2018 14:23:22 -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; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=IfI56sYj; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934282AbeFLVV3 (ORCPT + 99 others); Tue, 12 Jun 2018 17:21:29 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:46510 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932682AbeFLVV1 (ORCPT ); Tue, 12 Jun 2018 17:21:27 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id DB0AE8EE1E9; Tue, 12 Jun 2018 14:21:26 -0700 (PDT) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nw37WqPdzCg8; Tue, 12 Jun 2018 14:21:26 -0700 (PDT) Received: from [153.66.254.194] (unknown [50.35.68.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 6F4BA8EE0C8; Tue, 12 Jun 2018 14:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1528838486; bh=P46dzem9QUsqP5pxcvFdZcrRe70rv5guQ6CUuLeEb24=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=IfI56sYjlyYrwaGVOa+uiNBoMueuGVBhfM4xa/qqtKxTj79JLk+GbIoZ3XWEucYcF ijbpu1qi/gqn7I3gLI71f+sIq8FmwU4Wfd1B9q993dMJ3RXoIp9Jl1hMEsFAZOLCRi xUbpEzudtxtqI4hgUagiIIEbt6LJuHZsG0/WEJBE= Message-ID: <1528838485.24454.2.camel@HansenPartnership.com> Subject: Re: [PATCH] target: add error handling for match_int From: James Bottomley To: Zhouyang Jia Cc: "Nicholas A. Bellinger" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jun 2018 14:21:25 -0700 In-Reply-To: <1528779148-42485-1-git-send-email-jiazhouyang09@gmail.com> References: <1528779148-42485-1-git-send-email-jiazhouyang09@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-06-12 at 12:52 +0800, Zhouyang Jia wrote: > When match_int fails, the lack of error-handling code may > cause unexpected results. > > This patch adds error-handling code after calling match_int. > > Signed-off-by: Zhouyang Jia > --- >  drivers/target/target_core_rd.c | 6 ++++-- >  1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/target/target_core_rd.c > b/drivers/target/target_core_rd.c > index a6e8106..7bc89ff 100644 > --- a/drivers/target/target_core_rd.c > +++ b/drivers/target/target_core_rd.c > @@ -573,14 +573,16 @@ static ssize_t > rd_set_configfs_dev_params(struct se_device *dev, >   token = match_token(ptr, tokens, args); >   switch (token) { >   case Opt_rd_pages: > - match_int(args, &arg); > + if (match_int(args, &arg)) > + return -EINVAL; The first observation is that this would leak the kmalloc'd orig variable, but the second is that I don't think terminating parsing is the right thing to do even if match_int() returns an error: just ignoring this option and proceed to the next seems to be the best course because that's what we do with unrecognised options (the default: case). James