[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <546c0079-6b1c-9a67-a4c6-328eeb8c5ba7@gmail.com>
Date: Mon, 3 Apr 2023 23:58:41 +0900
From: Chanwoo Choi <cwchoi00@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Bumwoo Lee <bw365.lee@...sung.com>,
linux-kernel@...r.kernel.org
Cc: MyungJoo Ham <myungjoo.ham@...sung.com>,
Chanwoo Choi <cw00.choi@...sung.com>
Subject: Re: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()
On 23. 3. 22. 23:39, Andy Shevchenko wrote:
> 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;
The extcon cable information should be included in struct extcon_cable
in order to gather information into one point like encapsulation.
I don't prefer to add 'cable_names'.
>
> /* /sys/class/extcon/.../mutually_exclusive/... */
> struct attribute_group attr_g_muex;
--
Best Regards,
Samsung Electronics
Chanwoo Choi
Powered by blists - more mailing lists