From patchwork Wed Jun 28 15:32:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 697859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A1FCC001B0 for ; Wed, 28 Jun 2023 15:32:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232130AbjF1Pcn (ORCPT ); Wed, 28 Jun 2023 11:32:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:19758 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232237AbjF1Pc3 (ORCPT ); Wed, 28 Jun 2023 11:32:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687966349; x=1719502349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rkrFpsjN1kkwBUnx7S3/fsHajYxtZIFrVprJT5SR/KE=; b=myF5HRdh4ExUsTpMp5jYDvV073JU4tiPyetpvTnSXHKGX7LzGnw2i8hK NG+kpMfNUWkzo4xTe/MzYFiaCRp5lIrMcpyE4ZGEa2Yqnz4NyZaAHgFak NdnDBp3NzsqDubH4EFMl107e/Hie18dZTyWek/Tb11wEKP589SYq99oqc TQgieB2fjJuEXpL7Uyz8MIQNlsK4Wn9bABnQ+9S6yn8xXcJ0H3Yqya+Ii xdr3isOj7hkq3R7lq8konJu3VXHWe+vVPDHvubyc/k5iFaGnMn45LMdGo SjKx6waTNgYMnS4uTAuBF/4bbxxV1PFakpiYhgLkXl9CWIl+1Tuj5SWgF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="364427011" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="364427011" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 08:32:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="782344682" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="782344682" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 28 Jun 2023 08:32:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8D4EE93; Wed, 28 Jun 2023 18:32:14 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Saravana Kannan , Andy Shevchenko , Stephen Boyd , Dario Binacchi , Tony Lindgren , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org Cc: "Rafael J. Wysocki" , Peter De Schrijver , Prashant Gaikwad , Michael Turquette , Thierry Reding , Jonathan Hunter , Tero Kristo , Andy Shevchenko Subject: [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper Date: Wed, 28 Jun 2023 18:32:08 +0300 Message-Id: <20230628153211.52988-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> References: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Duplicate a NULL-terminated string and replace all occurrences of the old character with a new one. In other words, provide functionality of kstrdup() + strreplace(). Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 2 ++ lib/string_helpers.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 789ab30045da..9d1f5bb74dd5 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -109,6 +109,8 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); char *kstrdup_quotable_file(struct file *file, gfp_t gfp); +char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp); + char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n); void kfree_strarray(char **array, size_t n); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index d3b1dd718daf..9982344cca34 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -719,6 +719,21 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) } EXPORT_SYMBOL_GPL(kstrdup_quotable_file); +/* + * Returns duplicate string in which the @old characters are replaced by @new. + */ +char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp) +{ + char *dst; + + dst = kstrdup(src, gfp); + if (!dst) + return NULL; + + return strreplace(dst, old, new); +} +EXPORT_SYMBOL_GPL(kstrdup_and_replace); + /** * kasprintf_strarray - allocate and fill array of sequential strings * @gfp: flags for the slab allocator From patchwork Wed Jun 28 15:32:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 697619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45934C001B1 for ; Wed, 28 Jun 2023 15:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjF1Pcr (ORCPT ); Wed, 28 Jun 2023 11:32:47 -0400 Received: from mga09.intel.com ([134.134.136.24]:19763 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbjF1PcZ (ORCPT ); Wed, 28 Jun 2023 11:32:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687966345; x=1719502345; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ICZEGmnjo8mIWqvcZaLyV+IHFzcjkKGkir9xoI+1F50=; b=Pe4JDV6hj+t1pbcIG166ayBe1LxLcekIvU0GVBDZPgQHgc724ZKeJGdd NqtufppbfzFRrOEYRHgDEv+hKCnmEZPYeJG55DTZEpo971gGfja5X57ye GdULcXQrxQzGgSKNBblr0hDwRRicqhcbRpI+X4CCbeu0CkJv2kK6QdzaI 4J77zu67GDvCqejQU1OAgGiEU6wHwuzOXFPWi6XtLuFIsvKdlswo8FcjQ 1nHqqcn1GApCU8wV9P1ZewlTl1qDX8niBqYx6p6hS+0Dq9XC0v1rIMpw8 ELLY+gm+NfoCZI42izQCEnNcnI6cQQMBzweWCOEN1t7rNR478AO58GZdP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="364426989" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="364426989" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 08:32:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="782344681" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="782344681" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 28 Jun 2023 08:32:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 967CE4DA; Wed, 28 Jun 2023 18:32:14 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Saravana Kannan , Andy Shevchenko , Stephen Boyd , Dario Binacchi , Tony Lindgren , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org Cc: "Rafael J. Wysocki" , Peter De Schrijver , Prashant Gaikwad , Michael Turquette , Thierry Reding , Jonathan Hunter , Tero Kristo , Andy Shevchenko Subject: [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace() Date: Wed, 28 Jun 2023 18:32:09 +0300 Message-Id: <20230628153211.52988-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> References: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Replace open coded functionalify of kstrdup_and_replace() with a call. Signed-off-by: Andy Shevchenko Acked-by: Greg Kroah-Hartman --- drivers/base/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 3dff5037943e..af0ee691520a 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include #include /* for dma_default_coherent */ @@ -3910,10 +3910,9 @@ const char *device_get_devnode(const struct device *dev, return dev_name(dev); /* replace '!' in the name with '/' */ - s = kstrdup(dev_name(dev), GFP_KERNEL); + s = kstrdup_and_replace(dev_name(dev), '!', '/', GFP_KERNEL); if (!s) return NULL; - strreplace(s, '!', '/'); return *tmp = s; } From patchwork Wed Jun 28 15:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 697620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E24EC001DB for ; Wed, 28 Jun 2023 15:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbjF1Pcp (ORCPT ); Wed, 28 Jun 2023 11:32:45 -0400 Received: from mga09.intel.com ([134.134.136.24]:19758 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbjF1PcX (ORCPT ); Wed, 28 Jun 2023 11:32:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687966343; x=1719502343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cHot3HUA6uOrNhNVHxLnKbqcAV9rKZZMtPBuH3yLtBI=; b=eI/yEPUZBMd4LGNsuMkMpQ2uOlQWJ/FyS7eO//dYWg5b02w12C2aie+s qcrCVe4NOsGcvyn47h5k5h4kCUP+yYDXv7UdjOJwuQAhFKPESHrRa6ru8 WRuPN5NL++PdUkWCq4zvHfnnoEJ0m+1keDzyp8ObMH+DXvdICHpMUav9U ApohsoA8Rqk2/jXzbfazYPhUTOS3ZpGIPaa1vKDCBKZRLZ4Rs9vgUKFMO VWpHzCTXMCWuLDBbtOH3k9tp2YukOL0DInSF+nbfy9lK1xxFsr7/viEAM RE5Ras541Wx56zaZKGOgTEivYW3Q1VC3DiouxfRdrS8kAag0gGe3KBHik Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="364426966" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="364426966" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 08:32:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="782344683" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="782344683" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 28 Jun 2023 08:32:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9FBAE516; Wed, 28 Jun 2023 18:32:14 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Saravana Kannan , Andy Shevchenko , Stephen Boyd , Dario Binacchi , Tony Lindgren , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org Cc: "Rafael J. Wysocki" , Peter De Schrijver , Prashant Gaikwad , Michael Turquette , Thierry Reding , Jonathan Hunter , Tero Kristo , Andy Shevchenko Subject: [PATCH v1 3/4] clk: tegra: Replace kstrdup() + strreplace() with kstrdup_and_replace() Date: Wed, 28 Jun 2023 18:32:10 +0300 Message-Id: <20230628153211.52988-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> References: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Replace open coded functionalify of kstrdup_and_replace() with a call. Signed-off-by: Andy Shevchenko --- drivers/clk/tegra/clk.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c index 26bda45813c0..071e72d1598a 100644 --- a/drivers/clk/tegra/clk.c +++ b/drivers/clk/tegra/clk.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include @@ -384,12 +384,10 @@ static struct device_node *tegra_clk_get_of_node(struct clk_hw *hw) struct device_node *np; char *node_name; - node_name = kstrdup(hw->init->name, GFP_KERNEL); + node_name = kstrdup_and_replace(hw->init->name, '_', '-', GFP_KERNEL); if (!node_name) return NULL; - strreplace(node_name, '_', '-'); - for_each_child_of_node(tegra_car_np, np) { if (!strcmp(np->name, node_name)) break; From patchwork Wed Jun 28 15:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 697858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 632D0EB64D7 for ; Wed, 28 Jun 2023 15:32:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbjF1Pcq (ORCPT ); Wed, 28 Jun 2023 11:32:46 -0400 Received: from mga02.intel.com ([134.134.136.20]:53515 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232234AbjF1Pc3 (ORCPT ); Wed, 28 Jun 2023 11:32:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687966348; x=1719502348; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1tDiKollzsfCXGV+rVmP0hmFqWtqHNqcUethxH+1FHg=; b=GApZaMPlGRGY8SSVi8X594qIiWkpDh388LSvIQOwJ9BNCe7uXIkjucry UXFZ2IPswT787HTNF72SSsVTaIVI2yHhQMu5yexveYM52A7jpfFP7CZnc P+0ixHmBDsdr2YGPzHiOHf6rK0V/Bi8i3PrO4MHv7xN62m+d6Dy+fU40l AajzU5Bim1k7H57pDq9JDWUfijSxl0YgSEObe3wN4W1ZrRJHLb/RvpqU6 7j4G0DLcRONI3yJSb/HlxTLv99m1y6D3avqpBsVc/4zDkceHsB81yIibG bdBUMfidqtaAOBIMuOCUqqAIG24lby+JvPTBHp9gmPxFWY3UfG4A6otqd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="351666446" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="351666446" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 08:32:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="720270169" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="720270169" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 28 Jun 2023 08:32:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id ABFBB51E; Wed, 28 Jun 2023 18:32:14 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Saravana Kannan , Andy Shevchenko , Stephen Boyd , Dario Binacchi , Tony Lindgren , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-omap@vger.kernel.org Cc: "Rafael J. Wysocki" , Peter De Schrijver , Prashant Gaikwad , Michael Turquette , Thierry Reding , Jonathan Hunter , Tero Kristo , Andy Shevchenko Subject: [PATCH v1 4/4] clk: ti: Replace kstrdup() + strreplace() with kstrdup_and_replace() Date: Wed, 28 Jun 2023 18:32:11 +0300 Message-Id: <20230628153211.52988-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> References: <20230628153211.52988-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Replace open coded functionalify of kstrdup_and_replace() with a call. Signed-off-by: Andy Shevchenko --- drivers/clk/ti/clk.c | 4 ++-- drivers/clk/ti/clkctrl.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c index 3d636938a739..1862958ab412 100644 --- a/drivers/clk/ti/clk.c +++ b/drivers/clk/ti/clk.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -123,10 +124,9 @@ static struct device_node *ti_find_clock_provider(struct device_node *from, const char *n; char *tmp; - tmp = kstrdup(name, GFP_KERNEL); + tmp = kstrdup_and_replace(name, '-', '_', GFP_KERNEL); if (!tmp) return NULL; - strreplace(tmp, '-', '_'); /* Node named "clock" with "clock-output-names" */ for_each_of_allnodes_from(from, np) { diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c index 8c40f10280b7..607e34d8e289 100644 --- a/drivers/clk/ti/clkctrl.c +++ b/drivers/clk/ti/clkctrl.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "clock.h" @@ -473,11 +474,11 @@ static const char * __init clkctrl_get_name(struct device_node *np) const int prefix_len = 11; const char *compat; const char *output; + const char *end; char *name; if (!of_property_read_string_index(np, "clock-output-names", 0, &output)) { - const char *end; int len; len = strlen(output); @@ -491,13 +492,13 @@ static const char * __init clkctrl_get_name(struct device_node *np) of_property_for_each_string(np, "compatible", prop, compat) { if (!strncmp("ti,clkctrl-", compat, prefix_len)) { + end = compat + prefix_len; /* Two letter minimum name length for l3, l4 etc */ - if (strnlen(compat + prefix_len, 16) < 2) + if (strnlen(end, 16) < 2) continue; - name = kasprintf(GFP_KERNEL, "%s", compat + prefix_len); + name = kstrdup_and_replace(end, '-', '_', GFP_KERNEL); if (!name) continue; - strreplace(name, '-', '_'); return name; }