From patchwork Tue Sep 19 05:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 141795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3255916vqi; Tue, 19 Sep 2023 03:00:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1UPi+sVRD/Og140NZyESX1HbgtPJeqKNgaFWEPr9/UISt5Phz7ONdD07tq1NqwWxjYppl X-Received: by 2002:a17:902:d70a:b0:1b6:6f12:502e with SMTP id w10-20020a170902d70a00b001b66f12502emr10405216ply.49.1695117614900; Tue, 19 Sep 2023 03:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695117614; cv=none; d=google.com; s=arc-20160816; b=Y2Z8nxPLT0ieYPpNpOmV23MfeMDs1buxXKN9pvK54Ioo1SCNGT4ByRFMVl0QJd3ZpZ SdMjECwuBWUmZOfeFnpTfIFEPFtQqd+446rf1MMP1r86k3XC/MncCKWkzRtV9XerUvEK oRHUBzn6SbsJLajFXtHDK7ZsOEc82X2QYntYSNjH/4YRxn+Fazu0wCmqSEGbsuLWtEOQ Wbev0C/xyZZDCgvsOLMM2KSrtYMaEvZ98vwlQTEhhjRYToqax4Fpm70fWLQPYTMHwcMQ y2z0TII/+/tjKaX0+J1uTW7wEtuKMH301CJMRoPpjySRiDTW5h7QTDx2/2meeC7+T6gA HuiA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+ONgWObKo5NbEUwKbwWBJxWXXFQ2LXOOuOi9XpmUiLY=; fh=FqHKG6lXQzaRwDzW2Qh+InZDP8T8SEoI11YO6x4TlKU=; b=QnhUzkSrHl/JHYT3Q6P45eg3NmEYoJ0A+MveXhLUf/Vh4nPOsd2DNd4D7Yt/fBmxiZ EzGDxL+fzlAq8oESoyooer46skbJ42gMJGNZ+f3yQXsvxyDfv/C5x+r2Hs0topezo7x6 dLEZv49Bcy+T9VHiC+IfP2iTEsdqhcqVhYhOguVvWkeAAYLzgydjks4idKXE/i3I8veH jPWD1gAW7UJkcSOFWoid2KOTe2YgvQQ8p2zVDIaHqCC+6dqtu8LtyfqgSU/3ZP42xG3x APPvZoPXfYco+2kniFAF73zldKBcpmWcdixX9af6qQYTgfNtuCuv6V+m2zAf3Qo+NlFH lxOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Pr7fg7BK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id kp3-20020a170903280300b001b55070e154si9472128plb.96.2023.09.19.03.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 03:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Pr7fg7BK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B417180E9EB9; Mon, 18 Sep 2023 22:45:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbjISFpe (ORCPT + 25 others); Tue, 19 Sep 2023 01:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjISFp3 (ORCPT ); Tue, 19 Sep 2023 01:45:29 -0400 Received: from smtp.smtpout.orange.fr (smtp-29.smtpout.orange.fr [80.12.242.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9C1119 for ; Mon, 18 Sep 2023 22:45:23 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id iTY0qaEMmvRSUiTY0qPDf2; Tue, 19 Sep 2023 07:45:22 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1695102322; bh=+ONgWObKo5NbEUwKbwWBJxWXXFQ2LXOOuOi9XpmUiLY=; h=From:To:Cc:Subject:Date; b=Pr7fg7BKwrXGBU+UQzw7eYkyx/PDNBvtoAkngAPPXsLhm1ZpxMCssQ0iEcTs1lWYN zj+tiAENj5aXaJsXeKuGmwLGwwoWugDJGb7B1sxlGby9lVix2TywjY7YKqpTsCQdDa 3Ho52N59jy9PTrCgkT3MpkmiNa41MSddiR5ihCz2xvolvYvnqxpOCK8+gheKZ/AyDg CREPMv9VDynsYCg3MEsJFIQcnCzIrUmyuvys0dDm/126g1NhPP/O7iwhIUjYR/oh3s tltzUHzsciDykl9nQkIR/DUqsdYaxKy3ws3a1oQ1iKySVcOgl5ksnlE8KBGyYaFymR 49X7bCNOOqgkA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 19 Sep 2023 07:45:22 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Alexander Shishkin , Maxime Coquelin , Alexandre Torgue Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH] stm class: Use memdup_user_nul() to simplify stm_char_policy_set_ioctl() Date: Tue, 19 Sep 2023 07:45:19 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 22:45:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777459648108407713 X-GMAIL-MSGID: 1777459648108407713 Instead of hand-writing kzalloc(size+1) + copy_from_user(size), use memdup_user_nul() that does the same with a few less lines of code. This also saves a useless zeroing of the allocated memory. Signed-off-by: Christophe JAILLET --- drivers/hwtracing/stm/core.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 534fbefc7f6a..3ee98208ea8f 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -739,19 +739,11 @@ static int stm_char_policy_set_ioctl(struct stm_file *stmf, void __user *arg) if (size < sizeof(*id) || size >= PATH_MAX + sizeof(*id)) return -EINVAL; - /* - * size + 1 to make sure the .id string at the bottom is terminated, - * which is also why memdup_user() is not useful here - */ - id = kzalloc(size + 1, GFP_KERNEL); + /* Make sure the .id string at the bottom is nul terminated. */ + id = memdup_user_nul(arg, size); if (!id) return -ENOMEM; - if (copy_from_user(id, arg, size)) { - ret = -EFAULT; - goto err_free; - } - if (id->__reserved_0 || id->__reserved_1) goto err_free;