Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3368582rdb; Wed, 13 Sep 2023 09:53:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYrWLcCMxUy/RZBdVsiWBwec60rFmFCqWd4zEBA8oqRMZlpI1bn1UVu/LKV9cWcuDgr/+N X-Received: by 2002:a05:6a00:1301:b0:68e:41e9:10be with SMTP id j1-20020a056a00130100b0068e41e910bemr3044818pfu.20.1694623988368; Wed, 13 Sep 2023 09:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694623988; cv=none; d=google.com; s=arc-20160816; b=mmYJ6MDMhofFlNkzxVj0vliHKafi1lIfVO2/RnX17CqlzlxDFtRCQQhCytwi2sKwVA F7SRRD8OfQSOw49UBvsEkYWixHsCjbB+ijjmIlCTenfwzSIA/bPwKn7t9qgLDc6oeKlF wiWzfqU3eBFSgQ/7YUwGlg240FPzFmy5gkD2+SaYMK35mWsAsA0UhIkbRULaVbmsFTtj +6hXU3MeRrQ2WnRyEhUnZ08f4ZTNXfVu+9+8dwqsL0d7YswmRvZ/PKDvxyNpSqgJVN59 q6nTCGvDyVU7M40cSgCDYab9sYJ2O6nH+ZyUIgXAQB0J//c7WcydwM5bVsnnwGWiHn60 SNyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=8A9HL+stgfNKGFGMeLF2z4Plw8VkJpZaGt91Sh1mq1Y=; fh=Ghay9nrRNBYl71j//wkZ95TqN2ihhonZLr/rbC/YN6U=; b=HPi1Rc6ljySxl5Tu3etZEuP4eeXszqlbPNt/5x+gMeLs6O9QUzsnKuY5WikLslOUdk akEK21UxEZQ/7VLAP1/xMPQFLlW4Jy8wMxUBjWPUnZiPXMu//gvTwXRkALSjDuXQCwhb Pg4H11AG35TYdcXkW7yX+2yr7Uk8ANPOxJHjF+x/XxdqnVG9fqpjZDD8e2GrRY0CK5eq yEoH3YMx99aFCZe6I2+GZJB2v/JImgRhHG0eV/CZGrBQIwKHtkR+2ypCM6B3+kB9QLY4 Ji6TOidmS8kyYgwp9YNS6VyqT+mXryWfe/rcpe1eUMdB6sAJgen+BnT2woSJFijnhAMG 54Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm2 header.b=rh3pCqE8; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Tw9onljh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k4-20020a654644000000b00573e3b0d3e3si10280766pgr.408.2023.09.13.09.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 09:53:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm2 header.b=rh3pCqE8; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Tw9onljh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A764181C70B8; Wed, 13 Sep 2023 06:16:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240850AbjIMNQw (ORCPT + 99 others); Wed, 13 Sep 2023 09:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240876AbjIMNQt (ORCPT ); Wed, 13 Sep 2023 09:16:49 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFBC31BCD; Wed, 13 Sep 2023 06:16:45 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 913AC320094A; Wed, 13 Sep 2023 09:16:42 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute5.internal (MEProxy); Wed, 13 Sep 2023 09:16:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squebb.ca; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1694611002; x=1694697402; bh=8A 9HL+stgfNKGFGMeLF2z4Plw8VkJpZaGt91Sh1mq1Y=; b=rh3pCqE8iPqjbrl5b5 vMFeTPEo5TbVPSk2kni3WdudfWZ6iYsk+1Z/9p5MiHTmzTacekEb8SYfwhcT/Cqk 6J6xnucx73ZGnB8AsO3QpjIVXoX2JesWuO08DD9GK+QUuQ+N8Q5ERDExv2knBahS A8ILM+Z4mR5+UCu+XaR0fTICklw/Nwblj5D10yoSXKakbks5412sr4/a4tnl3d+7 qCgIZni6AMK40PS85ZndzuhLb7zNIgkMbJIMtuA5YaPe/I0UKHE03JqG2/n5klLr ZlvwBAjYy1anUe5MP/uAKN031DVjBfv9izuyTpIveZCfSAOP7GN4CTDicmhN9iU+ NKJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1694611002; x=1694697402; bh=8A9HL+stgfNKG FGMeLF2z4Plw8VkJpZaGt91Sh1mq1Y=; b=Tw9onljhdYlLXnn3gGroxpKpxpiyR YYPMWG/WIM+brcigakvQQq2f4RxCebCqhJoXz3krBnbK2Iuf5fVcbzRzDfZ+hkw2 V64VeRojYjZkgnNNnf7WSxwwZweHWdfT/yrVsBvsPz1ztweJvIVmGyXfOjeFedbR W/mDWTy/G8JKLmeq/25EgDNGeSUAMsk5CiOiCWwNMSRzHJHtIwCIOS7efbXRstjF I/TCB9msQjYj+YgRltk119k+Yi5CGG7iS1ltN2nA9rQLVDId/WhktGUYfx3EvxCe 8blrO2A5zu6f2aob9CR7k5SOaaT9jCOlfsn/3ZYCNOeAInLClMpwl61dA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeikedgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfofgr rhhkucfrvggrrhhsohhnfdcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssg drtggrqeenucggtffrrghtthgvrhhnpeeiueefjeeiveetuddvkeetfeeltdevffevudeh ffefjedufedvieejgedugeekhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggr X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7A90BC6008B; Wed, 13 Sep 2023 09:16:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-745-g95dd7bea33-fm-20230905.001-g95dd7bea Mime-Version: 1.0 Message-Id: <28b5d008-c1b6-4be7-aabe-419d9a158492@app.fastmail.com> In-Reply-To: <20230913092701.440959-1-andriy.shevchenko@linux.intel.com> References: <20230913092701.440959-1-andriy.shevchenko@linux.intel.com> Date: Wed, 13 Sep 2023 09:15:36 -0400 From: "Mark Pearson" To: "Andy Shevchenko" , "Hans de Goede" , "platform-driver-x86@vger.kernel.org" , linux-kernel@vger.kernel.org Cc: "Mark Pearson" , "markgross@kernel.org" Subject: Re: [PATCH v1 1/2] platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace() Content-Type: text/plain 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 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 06:16:54 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 agentk.vger.email On Wed, Sep 13, 2023, at 5:27 AM, Andy Shevchenko wrote: > Replace open coded functionalify of kstrdup_and_replace() with a call. > > Signed-off-by: Andy Shevchenko > --- > drivers/platform/x86/think-lmi.c | 43 +++++++++++--------------------- > 1 file changed, 15 insertions(+), 28 deletions(-) > > diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c > index 79346881cadb..94a3c7a74bc4 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; > @@ -985,13 +976,11 @@ static ssize_t current_value_store(struct kobject *kobj, > if (!tlmi_priv.can_set_bios_settings) > 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); > - > /* Use lock in case multiple WMI operations needed */ > mutex_lock(&tlmi_mutex); > > @@ -1163,13 +1152,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, > -- > 2.40.0.1.gaa8946217a0b Thanks Andy - didn't know about that function and it looks like a great clean-up. I'll aim to test this out on some systems, but it looks good to me Mark