From nobody Tue Apr 7 14:06:12 2026 Received: from mailgw2.hygon.cn (unknown [101.204.27.37]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B01A1223DD4 for ; Thu, 26 Feb 2026 06:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.204.27.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772086272; cv=none; b=uAlimvSo+BYNUZibPUOVjtHTo0Cu3lUivb7SwpWtrDD92z287WcXPKegD67Hf19FBfceItYsdrZ1TyXXWGYSe4+N42N2Jpv1uyOEBxMCZlKRcOpba7t2c3soCgYbiWQc7XuaDJDeJnh5F12Bjia/EFqu+mBvVuo/jS0YDTEbQrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772086272; c=relaxed/simple; bh=pWcQoncMtGKoFDSVcFNN+4kh5wImkdwnDX3XPbG3MSI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Yicm5MX3aBKwAzINi+MndRif+MxaKPQAmVOriFmmwDLpxdsNULD9G+6csWz75lhkQWs6zZO5RmUcJO21ublUWSqh+UaqYrZaO4qCocI/Npq8mziZ7elJ4A+Wwc+zN+hX0/HOKWF5kU3cdYtK17SZ38AkkNeg811GtJ74TFvz3YE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hygon.cn; spf=pass smtp.mailfrom=hygon.cn; arc=none smtp.client-ip=101.204.27.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hygon.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hygon.cn Received: from maildlp1.hygon.cn (unknown [127.0.0.1]) by mailgw2.hygon.cn (Postfix) with ESMTP id 4fM0sB4lzPz1YHN2d; Thu, 26 Feb 2026 13:49:34 +0800 (CST) Received: from maildlp1.hygon.cn (unknown [172.23.18.60]) by mailgw2.hygon.cn (Postfix) with ESMTP id 4fM0sB3SrDz1YHN2d; Thu, 26 Feb 2026 13:49:34 +0800 (CST) Received: from cncheex04.Hygon.cn (unknown [172.23.18.114]) by maildlp1.hygon.cn (Postfix) with ESMTPS id 14ECB1642; Thu, 26 Feb 2026 13:49:28 +0800 (CST) Received: from BJ-HV00147.Hygon.cn (172.18.22.73) by cncheex04.Hygon.cn (172.23.18.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Thu, 26 Feb 2026 13:49:32 +0800 From: To: , , CC: , , , , , , wangguangju Subject: [PATCH] Use kstrtouint_from_user() instead of open-coded copy_from_user() + kstrtouint() sequence. Date: Thu, 26 Feb 2026 13:49:04 +0800 Message-ID: <20260226054904.155924-1-wangguangju@hygon.cn> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: cncheex06.Hygon.cn (172.23.18.116) To cncheex04.Hygon.cn (172.23.18.114) Content-Type: text/plain; charset="utf-8" From: wangguangju This simplifies the code and avoids open-coded buffer handling. Signed-off-by: wangguangju --- arch/x86/mm/pkeys.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c index 7418c367e328..c7a2503dfc16 100644 --- a/arch/x86/mm/pkeys.c +++ b/arch/x86/mm/pkeys.c @@ -140,19 +140,12 @@ static ssize_t init_pkru_read_file(struct file *file,= char __user *user_buf, static ssize_t init_pkru_write_file(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { - char buf[32]; - ssize_t len; u32 new_init_pkru; + int ret; =20 - len =3D min(count, sizeof(buf) - 1); - if (copy_from_user(buf, user_buf, len)) - return -EFAULT; - - /* Make the buffer a valid string that we can not overrun */ - buf[len] =3D '\0'; - if (kstrtouint(buf, 0, &new_init_pkru)) - return -EINVAL; - + ret =3D kstrtouint_from_user(user_buf, count, 0, &new_init_pkru); + if (ret) + return ret; /* * Don't allow insane settings that will blow the system * up immediately if someone attempts to disable access --=20 2.43.0