Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3248840rdb; Wed, 13 Sep 2023 06:46:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG/pmRTDieeRNM/98QRniSW8Uppw3dRgH1hVvuU8EuZbTxKH5bC2BRIyG1PpgaOtLoe+VL X-Received: by 2002:a05:6a21:a59a:b0:131:b3fa:eaaa with SMTP id gd26-20020a056a21a59a00b00131b3faeaaamr3108214pzc.61.1694612796419; Wed, 13 Sep 2023 06:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694612796; cv=none; d=google.com; s=arc-20160816; b=EXriyXV12GNkptzE8hWaoviRWhZa6PJL9IwzpFcSlqJhScE5ZeOiCSoXCmsH8mZldL vV+hGXxSW/ZD4Cu1ej3vN3it7Il1mFAyP8bCqot+CwDcdWZ0ZSwzN13ILzgEdIJp4zec ZqL/wsNhr7+BmTTIiS1O6D/btmujtRAo50sQPSLF84UFyZ4HtqUIpdDlLXxFko5R59xY NVjlKifm7eJsDIiedCjKb4JtyKw5P5ze/shraflRhhF4q0YCQlpddpyYC3QDPgfbGwPQ 9q/Tf8ilj3GsOPGwwcgr50Rr62+Dhp5kuh+1gWKiLxmLGwnJDM1chILW6L1OtblmGSfy c8Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xmLCbym+hFmx0VXHXqJoCDtUuUHCGwrHxAPP129WuPQ=; fh=mXCtX0guzfa9IhNQV5qbsRksDFlHtEs5zpKlU3hivCQ=; b=FV4iA0UZ8uqw1b5ZeuteGTR+nhyNuWzUYLBQ8ifVQsO5ng2CQimX+hoyjTe5KQuPCF uaqd0mQkYYIf/knDCnUmo1VUJOizadcIudUPLItbOxcWk5gPDB4n2VOEdSfxH8FpELBK apXv2SFOPXHHFsLSIK5tzKqEyRQ0OKMlUBuO3vYzbUKU9x5bZXhztXEgxRgucjCq3PIC ASG/m+LPlzSY8VjldtncrNvUatK00PhauvMBQsphxSvrxEpiCosCF+snS2yI2poYgN4O tXnVxm31Jxut2s+SgGP40i7bRzp4b//WLpuxIJGA62sq7rT4imkdqBkbP0u9v5VaXF1y EPUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="CWhMvJt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id y24-20020a056a001c9800b0068fb4615f09si7013226pfw.328.2023.09.13.06.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 06:46:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="CWhMvJt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 79E5281F06B4; Wed, 13 Sep 2023 02:27:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239307AbjIMJ1M (ORCPT + 99 others); Wed, 13 Sep 2023 05:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239259AbjIMJ1L (ORCPT ); Wed, 13 Sep 2023 05:27:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8445199E; Wed, 13 Sep 2023 02:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694597227; x=1726133227; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=jWur+JX9CJPEdIOhhwD8UkpAw5f715+nAiJqnxYPswY=; b=CWhMvJt/BmdxMJT1BxTe6I5ZLpmsdey+f7kaN8kPU1A1GiHK/vqg/r9w 0jxMGDZGhqWqWahQQS1kVSJsO2f67vz1LGfa1AzHG/1Gq7UY0bK6JS7s/ RmacgYmw7djStn0Y7q94+V5vcO2OFc3iXvswOkznbHsuxlSVKDqvravV7 OFDlstJ8QHjHaWMU3YcXPNrrgZjofr/3eZroCXbvdXh6MnLaINgBVm6ZA ghSQP0BuGgKdzy6aArLSwkr5FJIkMYV6kWf3xmqTGKlNSUJVMYk5pPV14 82z2btdfjMF8zujclpJG+dq83wWnKC/Zg/x1x+UFCUoRLpR4kW5jB4/MR A==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="464979127" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="464979127" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 02:27:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="867717321" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="867717321" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 13 Sep 2023 02:27:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A3A331E5; Wed, 13 Sep 2023 12:27:03 +0300 (EEST) From: Andy Shevchenko To: Hans de Goede , Mark Pearson , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mark Pearson , Mark Gross , Andy Shevchenko Subject: [PATCH v1 1/2] platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace() Date: Wed, 13 Sep 2023 12:27:00 +0300 Message-Id: <20230913092701.440959-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 (fry.vger.email [0.0.0.0]); Wed, 13 Sep 2023 02:27:13 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 fry.vger.email 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