Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/x86: dell-wmi-sysman: Clean up security buffer helpers

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 <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260331160310.608857-3-thorsten.blum@linux.dev
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Thorsten Blum and committed by
Ilpo Järvinen
2d582157 955165c3

+12 -14
+2 -2
drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h
··· 189 189 int init_bios_attr_set_interface(void); 190 190 int map_wmi_error(int error_code); 191 191 size_t calculate_string_buffer(const char *str); 192 - size_t calculate_security_buffer(char *authentication); 193 - void populate_security_buffer(char *buffer, char *authentication); 192 + size_t calculate_security_buffer(const char *authentication); 193 + void populate_security_buffer(char *buffer, const char *authentication); 194 194 ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str); 195 195 int set_new_password(const char *password_type, const char *new); 196 196 int init_bios_attr_pass_interface(void);
+10 -12
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
··· 7 7 8 8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 9 10 + #include <linux/align.h> 10 11 #include <linux/fs.h> 11 12 #include <linux/dmi.h> 12 13 #include <linux/module.h> 13 14 #include <linux/kernel.h> 15 + #include <linux/string.h> 14 16 #include <linux/sysfs.h> 15 17 #include <linux/wmi.h> 16 18 #include "dell-wmi-sysman.h" ··· 75 73 * 76 74 * Currently only supported type is Admin password 77 75 */ 78 - size_t calculate_security_buffer(char *authentication) 76 + size_t calculate_security_buffer(const char *authentication) 79 77 { 80 - if (strlen(authentication) > 0) { 81 - return (sizeof(u32) * 2) + strlen(authentication) + 82 - strlen(authentication) % 2; 83 - } 84 - return sizeof(u32) * 2; 78 + return sizeof(u32) * 2 + ALIGN(strlen(authentication), 2); 85 79 } 86 80 87 81 /** ··· 87 89 * 88 90 * Currently only supported type is PLAIN TEXT 89 91 */ 90 - void populate_security_buffer(char *buffer, char *authentication) 92 + void populate_security_buffer(char *buffer, const char *authentication) 91 93 { 94 + size_t seclen = strlen(authentication); 92 95 char *auth = buffer + sizeof(u32) * 2; 93 96 u32 *sectype = (u32 *) buffer; 94 - u32 *seclen = sectype + 1; 97 + u32 *seclenp = sectype + 1; 95 98 96 - *sectype = strlen(authentication) > 0 ? 1 : 0; 97 - *seclen = strlen(authentication); 99 + *sectype = !!seclen; 100 + *seclenp = seclen; 98 101 99 102 /* plain text */ 100 - if (strlen(authentication) > 0) 101 - memcpy(auth, authentication, *seclen); 103 + memcpy(auth, authentication, seclen); 102 104 } 103 105 104 106 /**