public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bumwoo Lee <bw365.lee@samsung.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>
Subject: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()
Date: Wed, 22 Mar 2023 16:39:59 +0200	[thread overview]
Message-ID: <20230322144005.40368-9-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230322144005.40368-1-andriy.shevchenko@linux.intel.com>

Since we have a generic helper, switch the module to use it.
No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/extcon/extcon.c | 25 +++++++++++--------------
 drivers/extcon/extcon.h |  1 +
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 0d261ec6c473..a63e7eef02fd 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -23,6 +23,7 @@
 #include <linux/err.h>
 #include <linux/of.h>
 #include <linux/slab.h>
+#include <linux/string_helpers.h>
 #include <linux/sysfs.h>
 
 #include "extcon.h"
@@ -1104,19 +1105,17 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
 	if (!edev->cables)
 		return -ENOMEM;
 
+	edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported);
+	if (!edev->cable_names) {
+		kfree(edev->cables);
+		return -ENOMEM;
+	}
+
 	for (index = 0; index < edev->max_supported; index++) {
 		cable = &edev->cables[index];
 
-		str = kasprintf(GFP_KERNEL, "cable.%d", index);
-		if (!str) {
-			for (index--; index >= 0; index--) {
-				cable = &edev->cables[index];
-				kfree(cable->attr_g.name);
-			}
-
-			kfree(edev->cables);
-			return -ENOMEM;
-		}
+		str = edev->cable_names[index];
+		strreplace(str, '-', '.');
 
 		cable->edev = edev;
 		cable->cable_index = index;
@@ -1341,8 +1340,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 err_alloc_muex:
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 	if (edev->max_supported)
 		kfree(edev->cables);
 err_alloc_cables:
@@ -1387,8 +1385,7 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 
 	if (edev->max_supported) {
 		kfree(edev->extcon_dev_type.groups);
diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h
index 877c0860e300..5624f65ba17a 100644
--- a/drivers/extcon/extcon.h
+++ b/drivers/extcon/extcon.h
@@ -58,6 +58,7 @@ struct extcon_dev {
 	/* /sys/class/extcon/.../cable.n/... */
 	struct device_type extcon_dev_type;
 	struct extcon_cable *cables;
+	char **cable_names;
 
 	/* /sys/class/extcon/.../mutually_exclusive/... */
 	struct attribute_group attr_g_muex;
-- 
2.40.0.1.gaa8946217a0b


  parent reply	other threads:[~2023-03-22 14:39 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 14:39 [PATCH v1 00/14] extcon: Core cleanups and documentation fixes Andy Shevchenko
2023-03-22 14:39 ` [PATCH v1 01/14] extcon: Fix kernel doc of property fields to avoid warnings Andy Shevchenko
2023-04-03 13:50   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 02/14] extcon: Fix kernel doc of property capability " Andy Shevchenko
2023-04-03 13:51   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 03/14] extcon: Use DECLARE_BITMAP() to declare bit arrays Andy Shevchenko
2023-04-03 14:04   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 04/14] extcon: use sysfs_emit() to instead of sprintf() Andy Shevchenko
2023-04-03 14:10   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 05/14] extcon: Amend kernel documentation of struct extcon_dev Andy Shevchenko
2023-04-03 14:10   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 06/14] extcon: Allow name to be assigned outside of the framework Andy Shevchenko
2023-04-03 13:56   ` Chanwoo Choi
2023-03-22 14:39 ` [PATCH v1 07/14] extcon: Use unique number for the extcon device ID Andy Shevchenko
2023-04-03 14:52   ` Chanwoo Choi
2023-04-05 15:03     ` Andy Shevchenko
2023-03-22 14:39 ` Andy Shevchenko [this message]
2023-04-03 14:58   ` [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray() Chanwoo Choi
2023-04-05  8:16     ` Andy Shevchenko
2023-04-05 15:05       ` Andy Shevchenko
2023-03-22 14:40 ` [PATCH v1 09/14] extcon: Use device_match_of_node() helper Andy Shevchenko
2023-04-03 14:14   ` Chanwoo Choi
2023-03-22 14:40 ` [PATCH v1 10/14] extcon: use dev_of_node(dev) instead of dev->of_node Andy Shevchenko
2023-04-03 14:17   ` Chanwoo Choi
2023-03-22 14:40 ` [PATCH v1 11/14] extcon: Remove dup device name in the message and unneeded error check Andy Shevchenko
2023-04-03 14:59   ` Chanwoo Choi
2023-03-22 14:40 ` [PATCH v1 12/14] extcon: Use sizeof(*pointer) instead of sizeof(type) Andy Shevchenko
2023-04-03 14:32   ` Chanwoo Choi
2023-03-22 14:40 ` [PATCH v1 13/14] extcon: Drop unneeded assignments Andy Shevchenko
2023-04-03 15:06   ` Chanwoo Choi
2023-03-22 14:40 ` [PATCH v1 14/14] extcon: Use positive conditional in ternary operator Andy Shevchenko
2023-04-03 14:38   ` Chanwoo Choi
2023-04-05  8:18     ` Andy Shevchenko
2023-03-30 10:11 ` [PATCH v1 00/14] extcon: Core cleanups and documentation fixes Andy Shevchenko
2023-03-31  0:48   ` Bumwoo Lee
2023-04-05 23:17     ` Chanwoo Choi
2023-04-06  0:04       ` Bumwoo Lee
2023-04-06 10:49       ` 'Andy Shevchenko'
2023-04-03 13:58 ` Chanwoo Choi
2023-04-05  8:12   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230322144005.40368-9-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bw365.lee@samsung.com \
    --cc=cw00.choi@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox