Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp214244rdb; Mon, 18 Sep 2023 12:42:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCnwIXyphGX7K5gVlimHEq0AsrD/G8ESZHmOx76Df1UsvCqTZ/FKUXdCH4GfJicVTiNvkq X-Received: by 2002:a17:90a:f401:b0:268:4485:c868 with SMTP id ch1-20020a17090af40100b002684485c868mr8050266pjb.49.1695066137000; Mon, 18 Sep 2023 12:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695066136; cv=none; d=google.com; s=arc-20160816; b=Xl+lLbSl0idM9J8C0GwbVLsjYkIu8VmWyFLZBrM21j0ARFvyPa01QtIQR1LVkKEELL sAOmwSq6cwR0C8/6ElztIzUjDE4TLGZMlWDx0RiCeJ8CDnlZywZmgVoBMCV3w+OxjWgP tMlUIeyqgUnvr1iBLevup7GqlOrlltzreYU590/SgSe2nhnxEcBSfbzQklZXGlsBDoux 18YDUK2/TFjedN1UWzLDTuWgkFdj7u9bZjrMNl3fTcDKhd2d9AdvABmwWaKd+cK4SytG VQElWw7GcrEhh3+V8ydOFVPRrUQVOsMmK7vtKkMGJJ2PrWVlosnLu57QR4V0fl3D5QkF hQ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=SFTEO1gVuB0o9VqnZ24xUYBL6UVXB1fvcQlZJoLMNtg=; fh=fwr9ix3qxGvzRrULmNBmTQ64enyIPWPgzmqBwLOsUPs=; b=rAnsc3kkaWHAFyWQXwVbYqWESPGs763ikeE1hcH4AtSBAqxxiPNZPybEIhOhffm/A9 uPUSNBJcUdSfHZFqYt0wukoIwFyobQ1L/no0BqDs29avzTIbNF+xCSN7QMPzcb4dB9rw D8jq2bMzfN3azwuaTWenDTx3Hued/gqbdSokirbC2bUyA3PD0I/jni42RV2EjZ2nf0IS IzG7dk3Qt6IV8YG9dQ/Pv2+mzs41HBh/Ci9wIw/MR+XjnjGZQB9+SEUhBRJPpUrmTuCM sFl/mr2kXm87z1lCGIYIkH/FjuqAWjkh8mwVW6sbSNr1Sm+xWuSAvxwgHeJUz6Ql4r4T EtEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OzOgZGOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h63-20020a638342000000b00578a56a39dbsi562127pge.409.2023.09.18.12.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OzOgZGOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 722818078314; Mon, 18 Sep 2023 09:40:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbjIRQk3 (ORCPT + 99 others); Mon, 18 Sep 2023 12:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjIRQkE (ORCPT ); Mon, 18 Sep 2023 12:40:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C249630EC for ; Mon, 18 Sep 2023 09:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695053440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SFTEO1gVuB0o9VqnZ24xUYBL6UVXB1fvcQlZJoLMNtg=; b=OzOgZGOGf0qtrTDJuSZ6lMYXTRTTAtqgKY3kp2nX01kDXYQUx+GZEUu8t89p2kJGoqNEHy W4lUfXsO3coRuvdu/yMLkwUVBMw7hryiqLUYjy7g+ApEQBtTeDUHqExDmI2wKoIK7IcX27 K3tjzR+5cEodLgPwg3UVSuk9BXLgB3I= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-QXdKVKlRMXWcb7YiohMvbw-1; Mon, 18 Sep 2023 10:09:44 -0400 X-MC-Unique: QXdKVKlRMXWcb7YiohMvbw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-94a34d3e5ebso293170066b.3 for ; Mon, 18 Sep 2023 07:09:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695046182; x=1695650982; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SFTEO1gVuB0o9VqnZ24xUYBL6UVXB1fvcQlZJoLMNtg=; b=OAZ/LAT3grAF0nebORiDZMlBIJ/6SaGpGkAi9MBUUIZICir5G/RhhpBbk7BCAKWmXK imCr9DRjAlw4zZ2Y9K/q6Adn6Dso2TvuB8HfVRcCsV95tTQMyg2ugZVjxWV+P9vNqh9h hW6JL34++3yhWICHBtdd6DQvFICk/5hYdbsXYi8bDRuWdmJdn9UsYTv8GtGwI+tU9w6x LCe9geT53q2uKdKBbbPoYLzMNDUBa7NcK3rb3au4kshKCYjh9W4l4h4MS3akXpshDjYp /ZsA6ZXL76oUUYVEjD54GYaYKBVBZF79RvA94xOAbSjQCOUhxvOP8nluZkAtVw9jNPgH iVog== X-Gm-Message-State: AOJu0YxX8gWAjYzn22uRocuhb+hOysio86JsbgvjCdm7T4aO5zFYHKCc oJotcbChSgzt26sjdlTJDPWMILHDZssScDRgE6P+zrunIgCS3I6WFPtQgG0Y/f2hvY64RnWvD/U qwMfceEILAbVE6yqRXr9f+/6bPMkcnaJn X-Received: by 2002:a17:907:2cec:b0:9a5:ca17:b586 with SMTP id hz12-20020a1709072cec00b009a5ca17b586mr7679572ejc.34.1695046182278; Mon, 18 Sep 2023 07:09:42 -0700 (PDT) X-Received: by 2002:a17:907:2cec:b0:9a5:ca17:b586 with SMTP id hz12-20020a1709072cec00b009a5ca17b586mr7679560ejc.34.1695046181993; Mon, 18 Sep 2023 07:09:41 -0700 (PDT) Received: from [10.40.98.142] ([78.108.130.194]) by smtp.gmail.com with ESMTPSA id dv7-20020a170906b80700b0099b8234a9fesm6553239ejb.1.2023.09.18.07.09.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Sep 2023 07:09:40 -0700 (PDT) Message-ID: Date: Mon, 18 Sep 2023 16:09:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2 1/2] platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace() Content-Language: en-US To: Andy Shevchenko , Mark Pearson , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mark Pearson , Mark Gross , =?UTF-8?Q?Ilpo_J=c3=a4rvinen?= References: <20230918135116.1248560-1-andriy.shevchenko@linux.intel.com> From: Hans de Goede In-Reply-To: <20230918135116.1248560-1-andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:40:42 -0700 (PDT) Hi Andy, On 9/18/23 15:51, Andy Shevchenko wrote: > Replace open coded functionalify of kstrdup_and_replace() with a call. > > Reviewed-by: Ilpo Järvinen > Signed-off-by: Andy Shevchenko > --- > v2: rebased on top of review-hans (Hans), added tag (Ilpo) > drivers/platform/x86/think-lmi.c | 43 +++++++++++--------------------- > 1 file changed, 15 insertions(+), 28 deletions(-) Thank you for the new version. Thank you for your patch-series, I've applied the series to my review-hans branch: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while. Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window. Regards, Hans > > diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c > index f69003c30fa2..4e0d52dc3944 100644 > --- a/drivers/platform/x86/think-lmi.c > +++ b/drivers/platform/x86/think-lmi.c > @@ -15,7 +15,7 @@ > #include > #include > #include > -#include > +#include > #include > #include > #include > @@ -432,13 +432,11 @@ static ssize_t new_password_store(struct kobject *kobj, > if (!tlmi_priv.can_set_bios_password) > return -EOPNOTSUPP; > > - new_pwd = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present, setting password won't work if it is present */ > + new_pwd = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_pwd) > return -ENOMEM; > > - /* Strip out CR if one is present, setting password won't work if it is present */ > - strip_cr(new_pwd); > - > /* Use lock in case multiple WMI operations needed */ > mutex_lock(&tlmi_mutex); > > @@ -709,13 +707,11 @@ static ssize_t cert_to_password_store(struct kobject *kobj, > if (!setting->signature || !setting->signature[0]) > return -EACCES; > > - passwd = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + passwd = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!passwd) > return -ENOMEM; > > - /* Strip out CR if one is present */ > - strip_cr(passwd); > - > /* Format: 'Password,Signature' */ > auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature); > if (!auth_str) { > @@ -765,11 +761,10 @@ static ssize_t certificate_store(struct kobject *kobj, > return ret ?: count; > } > > - new_cert = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + new_cert = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_cert) > return -ENOMEM; > - /* Strip out CR if one is present */ > - strip_cr(new_cert); > > if (setting->cert_installed) { > /* Certificate is installed so this is an update */ > @@ -817,13 +812,11 @@ static ssize_t signature_store(struct kobject *kobj, > if (!tlmi_priv.certificate_support) > return -EOPNOTSUPP; > > - new_signature = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_signature) > return -ENOMEM; > > - /* Strip out CR if one is present */ > - strip_cr(new_signature); > - > /* Free any previous signature */ > kfree(setting->signature); > setting->signature = new_signature; > @@ -846,13 +839,11 @@ static ssize_t save_signature_store(struct kobject *kobj, > if (!tlmi_priv.certificate_support) > return -EOPNOTSUPP; > > - new_signature = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_signature) > return -ENOMEM; > > - /* Strip out CR if one is present */ > - strip_cr(new_signature); > - > /* Free any previous signature */ > kfree(setting->save_signature); > setting->save_signature = new_signature; > @@ -992,13 +983,11 @@ static ssize_t current_value_store(struct kobject *kobj, > if (tlmi_priv.save_mode == TLMI_SAVE_BULK && tlmi_priv.reboot_required) > return -EPERM; > > - new_setting = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_setting) > return -ENOMEM; > > - /* Strip out CR if one is present */ > - strip_cr(new_setting); > - > /* Use lock in case multiple WMI operations needed */ > mutex_lock(&tlmi_mutex); > > @@ -1279,13 +1268,11 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr > if (!tlmi_priv.can_debug_cmd) > return -EOPNOTSUPP; > > - new_setting = kstrdup(buf, GFP_KERNEL); > + /* Strip out CR if one is present */ > + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL); > if (!new_setting) > return -ENOMEM; > > - /* Strip out CR if one is present */ > - strip_cr(new_setting); > - > if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { > auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;", > tlmi_priv.pwd_admin->password,