From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF9523A3E74 for ; Thu, 2 Apr 2026 16:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775149203; cv=none; b=F29+540TW5z6ZV4LaQ2UOOzRJe1RQhov8dn0EI4m7PNL4P9YEueEDHBI2G551V5VE61kap1kXVrbQmE+SxQgKrTMxOHHVKVGngWg3jnLg+PU1F6IfnIJZ2pTqxYS96kVCJtA5JYTJl3gqgG0BNsyMslyFIpWSo8/JeXRRiYGRew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775149203; c=relaxed/simple; bh=qGdjIpAz9PgAQS+iKJwr9LbL9orJQc6FV29pmNDALJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jpt/rKxiwOqJw9adJf+3Kan5ls6earllDbtfGDIqhzjmDEddee4VqwBjLGI6JcltYeWwVl3Ce+I9NHNc+dJcizFEnEPUir2vT/Uy8YTt+lSxGkN8XGdkQ9KyXEzPy9rlrPT6napdtpLMuUV2n0AxoSbQIkWDapxDnbJHe4F7NEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wLFNlPAs; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wLFNlPAs" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775149194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTsnRkMDW4bN5OzJnPwtzF9uMoTldtikXKPNt9FXCXs=; b=wLFNlPAseUwuf223Pvge90E7pQq8MuSMmcLAK5R4mrgSf06ylW8xhI3jIjjHWvXHHUtAf9 pVggNBZUkO1/dYXF0NeWN0eF9xir6oTxcswh8DCFBRfJ8GNYq9NltjMjKl0qqvG3SkQ6Fi 0/ggIC5H3dfcfHLolphd4Vptmeg+MHI= From: Thorsten Blum To: Alexander Shishkin , Maxime Coquelin , Alexandre Torgue Cc: Thorsten Blum , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND 2/2] stm class: Replace kzalloc + copy_from_user with memdup_user_nul Date: Thu, 2 Apr 2026 18:59:36 +0200 Message-ID: <20260402165933.895706-5-thorsten.blum@linux.dev> In-Reply-To: <20260402165933.895706-4-thorsten.blum@linux.dev> References: <20260402165933.895706-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1139; i=thorsten.blum@linux.dev; h=from:subject; bh=qGdjIpAz9PgAQS+iKJwr9LbL9orJQc6FV29pmNDALJQ=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJnnFpTFW99V+pxed+lQ1vV7Hu/Su8s05Ayv5G/Lvi1rF evkkGDZUcrCIMbFICumyPJg1o8ZvqU1lZtMInbCzGFlAhnCwMUpABMR62ZkeK/R8nr6S50TvZNC kgJbt2W03z3/7nHAtZx6vzDjgEghOUaG2xynOu+cfjKrkleo2q7wbsbC7fyrzqzdl+Y2+eqbMxX 6jAA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to simplify and improve stm_char_policy_set_ioctl(). Remove the obsolete comment. Signed-off-by: Thorsten Blum --- drivers/hwtracing/stm/core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 49791024bb86..f2c0f2b8f7b1 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -733,18 +733,9 @@ 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); - if (!id) - return -ENOMEM; - - if (copy_from_user(id, arg, size)) { - ret = -EFAULT; - goto err_free; - } + id = memdup_user_nul(arg, size); + if (IS_ERR(id)) + return PTR_ERR(id); if (id->__reserved_0 || id->__reserved_1) goto err_free;