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: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace()

Replace open coded functionalify of kstrdup_and_replace() with a call.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230918135116.1248560-1-andriy.shevchenko@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Andy Shevchenko and committed by
Hans de Goede
e6211980 d5e2c233

+15 -28
+15 -28
drivers/platform/x86/think-lmi.c
··· 15 15 #include <linux/errno.h> 16 16 #include <linux/fs.h> 17 17 #include <linux/mutex.h> 18 - #include <linux/string.h> 18 + #include <linux/string_helpers.h> 19 19 #include <linux/types.h> 20 20 #include <linux/dmi.h> 21 21 #include <linux/wmi.h> ··· 432 432 if (!tlmi_priv.can_set_bios_password) 433 433 return -EOPNOTSUPP; 434 434 435 - new_pwd = kstrdup(buf, GFP_KERNEL); 435 + /* Strip out CR if one is present, setting password won't work if it is present */ 436 + new_pwd = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 436 437 if (!new_pwd) 437 438 return -ENOMEM; 438 - 439 - /* Strip out CR if one is present, setting password won't work if it is present */ 440 - strip_cr(new_pwd); 441 439 442 440 /* Use lock in case multiple WMI operations needed */ 443 441 mutex_lock(&tlmi_mutex); ··· 707 709 if (!setting->signature || !setting->signature[0]) 708 710 return -EACCES; 709 711 710 - passwd = kstrdup(buf, GFP_KERNEL); 712 + /* Strip out CR if one is present */ 713 + passwd = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 711 714 if (!passwd) 712 715 return -ENOMEM; 713 - 714 - /* Strip out CR if one is present */ 715 - strip_cr(passwd); 716 716 717 717 /* Format: 'Password,Signature' */ 718 718 auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature); ··· 761 765 return ret ?: count; 762 766 } 763 767 764 - new_cert = kstrdup(buf, GFP_KERNEL); 768 + /* Strip out CR if one is present */ 769 + new_cert = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 765 770 if (!new_cert) 766 771 return -ENOMEM; 767 - /* Strip out CR if one is present */ 768 - strip_cr(new_cert); 769 772 770 773 if (setting->cert_installed) { 771 774 /* Certificate is installed so this is an update */ ··· 812 817 if (!tlmi_priv.certificate_support) 813 818 return -EOPNOTSUPP; 814 819 815 - new_signature = kstrdup(buf, GFP_KERNEL); 820 + /* Strip out CR if one is present */ 821 + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 816 822 if (!new_signature) 817 823 return -ENOMEM; 818 - 819 - /* Strip out CR if one is present */ 820 - strip_cr(new_signature); 821 824 822 825 /* Free any previous signature */ 823 826 kfree(setting->signature); ··· 839 846 if (!tlmi_priv.certificate_support) 840 847 return -EOPNOTSUPP; 841 848 842 - new_signature = kstrdup(buf, GFP_KERNEL); 849 + /* Strip out CR if one is present */ 850 + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 843 851 if (!new_signature) 844 852 return -ENOMEM; 845 - 846 - /* Strip out CR if one is present */ 847 - strip_cr(new_signature); 848 853 849 854 /* Free any previous signature */ 850 855 kfree(setting->save_signature); ··· 983 992 if (tlmi_priv.save_mode == TLMI_SAVE_BULK && tlmi_priv.reboot_required) 984 993 return -EPERM; 985 994 986 - new_setting = kstrdup(buf, GFP_KERNEL); 995 + /* Strip out CR if one is present */ 996 + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 987 997 if (!new_setting) 988 998 return -ENOMEM; 989 - 990 - /* Strip out CR if one is present */ 991 - strip_cr(new_setting); 992 999 993 1000 /* Use lock in case multiple WMI operations needed */ 994 1001 mutex_lock(&tlmi_mutex); ··· 1268 1279 if (!tlmi_priv.can_debug_cmd) 1269 1280 return -EOPNOTSUPP; 1270 1281 1271 - new_setting = kstrdup(buf, GFP_KERNEL); 1282 + /* Strip out CR if one is present */ 1283 + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); 1272 1284 if (!new_setting) 1273 1285 return -ENOMEM; 1274 - 1275 - /* Strip out CR if one is present */ 1276 - strip_cr(new_setting); 1277 1286 1278 1287 if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { 1279 1288 auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",