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: 13390847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68C9CCD343C for ; Tue, 19 Sep 2023 05:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=gZUBWqmdsA9auv/DN+XJfaLdmACBmkHmz2VXnh+Eozs=; b=Bt16dr0FOE/qv8 ypgMhxK9dxEu3Yn4aMiLhkQx11Xg9UXzWJWHFX8ExPgJVABBVrHjVqa8VheC1UXiCMH2gBsOBrRjv 1qIykL4J0i9KTDaBbTamL2vUaw0ABnOPR28WIf6KREm8WNs1iqJtoBTjkQesc5nTFfzNZ/4H9z8Lu 5dWHddhw4Efu9w0pZRGzlG3Y/lrcQ7LJ45aryKADrE3dLaf6rqmHEHsska5kQmfzoqXe8hxKQf+TX 0UEcBYpjZiqB3F2wddpr1hc1KSUJ/+gjpGKZRHOTK/xk+mS8GK/Uo+DSOL0p6ohQHiINwsEBhcrbh W5z5rV7+baxaShTl2J8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiTY8-00H4ED-0l; Tue, 19 Sep 2023 05:45:28 +0000 Received: from smtp-30.smtpout.orange.fr ([80.12.242.30] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiTY5-00H4DC-1O for linux-arm-kernel@lists.infradead.org; Tue, 19 Sep 2023 05:45:27 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_224525_885756_F3A6F3EA X-CRM114-Status: GOOD ( 12.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;