From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 40CDC3F076B for ; Thu, 2 Apr 2026 16:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775149199; cv=none; b=KYmkdRUkFOZoNs5itr5LNJPM7d9F3zfVpyMUm+lANFaGj+eCFzkccGzKtd6s2SjwASlnlTxuB2nW3Ps+cdv5eCEwPriPuv7/WLZq2+Cm0vLgiE6gpk3pZowTEvOv1y/uuuqDGQSpz7ptb+xPylPQD9HXhME7vdHV93/74W/Ghek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775149199; c=relaxed/simple; bh=KGm3LCDb6uenDpT0wQR4w1aCAHUzrT837r/6S14WP6A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IVw7vr6eFNJ9pLU+tDEugqU4lNG/YFGuygCUu/yFVECDdZPzss7+6LMtaKDzJ5mwkMWVm4HZUEIEIWsdf5aNcLRis7tjyVKF0Olwca/dNvWjv6MV2QN49fi6kZVNDIO9uEDGUdf5MIpm11OdgQ6Au4+rieXmF5rhHmC/2eolhMo= 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=jhPLdVJ3; arc=none smtp.client-ip=91.218.175.186 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="jhPLdVJ3" 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=1775149192; 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; bh=hnQnlRNLWRBYJ2adhkVyrZB6k8P/ZToXFqlxV/C+eno=; b=jhPLdVJ3ZrNZYk3Pyt/IoBeHl4k5e3RUV8qzh5weS9XrgSLmTwfWasLfnWiTqts2mCqd6a Gxp9X/3iw9Eatu+/e6EIdNfcFtDnwmd+7A3qlK2BGUO+eNArIk+bTRPDZPHRWiyB/I0vh/ bjFbNLEEfTuwy6CIpbyTr+WZKFHR5hY= 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 1/2] stm class: Replace kmalloc + copy_from_user with memdup_user Date: Thu, 2 Apr 2026 18:59:35 +0200 Message-ID: <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=978; i=thorsten.blum@linux.dev; h=from:subject; bh=KGm3LCDb6uenDpT0wQR4w1aCAHUzrT837r/6S14WP6A=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJnnFpRe3nauPGqvvLiv1KTjYt2X3dqjf7suXOHAW3Ti9 F/ujTFKHaUsDGJcDLJiiiwPZv2Y4VtaU7nJJGInzBxWJpAhDFycAjCR+fMY/me4qykubbzvExdV dOPQ7Vn3tev2HFSUv/a5/ovLOcH+jJ2MDNtCHIKaYlc7NGzq8726P3t3f/Raw5WzV/dNnHyp5Lp MFxMA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Replace kmalloc() followed by copy_from_user() with memdup_user() to simplify and improve stm_char_write(). Allocate and copy only 'count' bytes instead of 'count + 1' since the extra byte is unused. Signed-off-by: Thorsten Blum --- drivers/hwtracing/stm/core.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 37584e786bb5..49791024bb86 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -645,15 +645,9 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf, return err; } - kbuf = kmalloc(count + 1, GFP_KERNEL); - if (!kbuf) - return -ENOMEM; - - err = copy_from_user(kbuf, buf, count); - if (err) { - kfree(kbuf); - return -EFAULT; - } + kbuf = memdup_user(buf, count); + if (IS_ERR(kbuf)) + return PTR_ERR(kbuf); pm_runtime_get_sync(&stm->dev);