lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230322144005.40368-9-andriy.shevchenko@linux.intel.com>
Date:   Wed, 22 Mar 2023 16:39:59 +0200
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Bumwoo Lee <bw365.lee@...sung.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        linux-kernel@...r.kernel.org
Cc:     MyungJoo Ham <myungjoo.ham@...sung.com>,
        Chanwoo Choi <cw00.choi@...sung.com>
Subject: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()

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

Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ