From nobody Wed Apr 1 09:43:12 2026 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 3C3F43A3E67 for ; Tue, 31 Mar 2026 16:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973030; cv=none; b=W8Q8JVqJqkvbLuOmSXw2GOJsYqm+mNNdpEpGniM7I9qwt/N7Xsav3pjVIqfcjWcS/020ygtZB1G+IcSjW9GyNWT/iWsepBIwEU9TsY8K9zrFC6ujaE2IQxGPgy6toZOoXGLZ2EVehT/bZhs7v1USP1FfHVskKKRS5FYirWzLZ4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774973030; c=relaxed/simple; bh=ZCrkXDETCpA21aqg5PlKDJZWG3TJkyEp4AYs5BsgfVM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PSfn9Go55jk3JInY2BFRY2vMJ3Ziv/iueXYV04cOaGCzm8yrG7zBJ9G7LmQbpVL+eWHqjs3xj3OG+m2mnqE+zuDkT7ZP/z808Sfy5gn+jN5eKRFVK7Tcl75S4NllX26jXv5IOYr2TZIzL6t4EkFiWSvG2u88rih9pj7pXVfBU2Q= 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=O50KzSuB; arc=none smtp.client-ip=91.218.175.173 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="O50KzSuB" 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=1774973026; 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=jn8MCJuE3cN7fDwMvTSZWk5jSOj+iSNPS3Lh5oSkVzY=; b=O50KzSuB7dt4Hd4+kX1HTUM6lB0zFoSEpbnO0hEF9PU6s5S4hQBvKhKhQeURKvYA/O8JD9 odaVC4u+MnoiMEz+JoQ7jHhg/LjTEj6MqwOz26dKdpm0B6avQXuEmYByOAdBkcKRBKCv1Z bqYApmmBIvun+tQnGvt3OGlKnPJgHqE= From: Thorsten Blum To: Prasanth Ksr , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Thorsten Blum , Dell.Client.Kernel@dell.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] platform/x86: dell-wmi-sysman: Clean up security buffer helpers Date: Tue, 31 Mar 2026 18:03:11 +0200 Message-ID: <20260331160310.608857-3-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=3629; i=thorsten.blum@linux.dev; h=from:subject; bh=ZCrkXDETCpA21aqg5PlKDJZWG3TJkyEp4AYs5BsgfVM=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJmnP9h1Luu/37Zym5JTqYRE5ds6/wuR/v8323Eu/HT0u +qsOU3TO0pZGMS4GGTFFFkezPoxw7e0pnKTScROmDmsTCBDGLg4BWAiz3MZGU70Gkbuq09w56lr NtY6dqpmC6t6XEHuEweJ9NQAw4mXfzAynNl908S6LtqQu2QTU7lVm/VJZ86Q3zerljsY+1xPUGr lBgA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" In calculate_security_buffer(), call strlen() once and use ALIGN() to round up to an even size. In populate_security_buffer(), also avoid recomputing strlen(), rename the u32 pointer from 'seclen' to 'seclenp' to avoid confusion with the new length variable, and drop the memcpy() guard since calling it with size 0 is a no-op and therefore safe. Use 'const char *' for the read-only source string in both helpers. Signed-off-by: Thorsten Blum --- Changes in v2: - Include headers (Ilpo) - Link to v1: https://lore.kernel.org/lkml/20260309211811.82403-3-thorsten.= blum@linux.dev/ --- .../dell/dell-wmi-sysman/dell-wmi-sysman.h | 4 ++-- .../x86/dell/dell-wmi-sysman/sysman.c | 22 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h b/= drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h index 817ee7ba07ca..5278a93fdaf7 100644 --- a/drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h +++ b/drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h @@ -189,8 +189,8 @@ void exit_bios_attr_set_interface(void); int init_bios_attr_set_interface(void); int map_wmi_error(int error_code); size_t calculate_string_buffer(const char *str); -size_t calculate_security_buffer(char *authentication); -void populate_security_buffer(char *buffer, char *authentication); +size_t calculate_security_buffer(const char *authentication); +void populate_security_buffer(char *buffer, const char *authentication); ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char= *str); int set_new_password(const char *password_type, const char *new); int init_bios_attr_pass_interface(void); diff --git a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c b/drivers/p= latform/x86/dell/dell-wmi-sysman/sysman.c index 9dddab6c9397..4ae37a1c77f4 100644 --- a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c @@ -7,10 +7,12 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include #include +#include #include #include "dell-wmi-sysman.h" #include "../../firmware_attributes_class.h" @@ -72,13 +74,9 @@ size_t calculate_string_buffer(const char *str) * * Currently only supported type is Admin password */ -size_t calculate_security_buffer(char *authentication) +size_t calculate_security_buffer(const char *authentication) { - if (strlen(authentication) > 0) { - return (sizeof(u32) * 2) + strlen(authentication) + - strlen(authentication) % 2; - } - return sizeof(u32) * 2; + return sizeof(u32) * 2 + ALIGN(strlen(authentication), 2); } =20 /** @@ -88,18 +86,18 @@ size_t calculate_security_buffer(char *authentication) * * Currently only supported type is PLAIN TEXT */ -void populate_security_buffer(char *buffer, char *authentication) +void populate_security_buffer(char *buffer, const char *authentication) { + size_t seclen =3D strlen(authentication); char *auth =3D buffer + sizeof(u32) * 2; u32 *sectype =3D (u32 *) buffer; - u32 *seclen =3D sectype + 1; + u32 *seclenp =3D sectype + 1; =20 - *sectype =3D strlen(authentication) > 0 ? 1 : 0; - *seclen =3D strlen(authentication); + *sectype =3D !!seclen; + *seclenp =3D seclen; =20 /* plain text */ - if (strlen(authentication) > 0) - memcpy(auth, authentication, *seclen); + memcpy(auth, authentication, seclen); } =20 /**