mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Lukasz Luba <lukasz.luba@arm.com>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	Jiri Pirko <jiri@nvidia.com>, Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	Amit Kucheria <amitk@kernel.org>,
	"open list:MELLANOX ETHERNET SWITCH DRIVERS"
	<netdev@vger.kernel.org>
Subject: Re: [PATCH v2 1/5] thermal/drivers/core: Use a char pointer for the cooling device name
Date: Fri, 12 Mar 2021 22:01:01 +0100	[thread overview]
Message-ID: <f51fcec0-1483-cecb-d984-591097c324ca@linaro.org> (raw)
In-Reply-To: <18fdc11b-abda-25d9-582f-de2f9dfa2feb@arm.com>

On 12/03/2021 19:49, Lukasz Luba wrote:
> 
> 
> On 3/12/21 5:03 PM, Daniel Lezcano wrote:
>> We want to have any kind of name for the cooling devices as we do no
>> longer want to rely on auto-numbering. Let's replace the cooling
>> device's fixed array by a char pointer to be allocated dynamically
>> when registering the cooling device, so we don't limit the length of
>> the name.
>>
>> Rework the error path at the same time as we have to rollback the
>> allocations in case of error.
>>
>> Tested with a dummy device having the name:
>>   "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch"
>>
>> A village on the island of Anglesey (Wales), known to have the longest
>> name in Europe.
>>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> ---
>>   .../ethernet/mellanox/mlxsw/core_thermal.c    |  2 +-
>>   drivers/thermal/thermal_core.c                | 38 +++++++++++--------
>>   include/linux/thermal.h                       |  2 +-
>>   3 files changed, 24 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
>> b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
>> index bf85ce9835d7..7447c2a73cbd 100644
>> --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
>> +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
>> @@ -141,7 +141,7 @@ static int mlxsw_get_cooling_device_idx(struct
>> mlxsw_thermal *thermal,
>>       /* Allow mlxsw thermal zone binding to an external cooling
>> device */
>>       for (i = 0; i < ARRAY_SIZE(mlxsw_thermal_external_allowed_cdev);
>> i++) {
>>           if (strnstr(cdev->type, mlxsw_thermal_external_allowed_cdev[i],
>> -                sizeof(cdev->type)))
>> +                strlen(cdev->type)))
>>               return 0;
>>       }
>>   diff --git a/drivers/thermal/thermal_core.c
>> b/drivers/thermal/thermal_core.c
>> index 996c038f83a4..9ef8090eb645 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -960,10 +960,7 @@ __thermal_cooling_device_register(struct
>> device_node *np,
>>   {
>>       struct thermal_cooling_device *cdev;
>>       struct thermal_zone_device *pos = NULL;
>> -    int result;
>> -
>> -    if (type && strlen(type) >= THERMAL_NAME_LENGTH)
>> -        return ERR_PTR(-EINVAL);
>> +    int ret;
>>         if (!ops || !ops->get_max_state || !ops->get_cur_state ||
>>           !ops->set_cur_state)
>> @@ -973,14 +970,17 @@ __thermal_cooling_device_register(struct
>> device_node *np,
>>       if (!cdev)
>>           return ERR_PTR(-ENOMEM);
>>   -    result = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);
>> -    if (result < 0) {
>> -        kfree(cdev);
>> -        return ERR_PTR(result);
>> +    ret = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);
>> +    if (ret < 0)
>> +        goto out_kfree_cdev;
>> +    cdev->id = ret;
>> +
>> +    cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
>> +    if (!cdev->type) {
>> +        ret = -ENOMEM;
> 
> Since we haven't called the device_register() yet, I would call here:
> kfree(cdev);
> and then jump

I'm not sure to understand, we have to remove the ida, no ?

> Other than that, LGTM
> 
> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
> 
> Regards,
> Lukasz


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

  reply	other threads:[~2021-03-12 21:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 17:03 Daniel Lezcano
2021-03-12 17:03 ` [PATCH v2 2/5] thermal/drivers/cpufreq_cooling: Use device name instead of auto-numbering Daniel Lezcano
2021-03-12 17:03 ` [PATCH v2 3/5] thermal/drivers/devfreq_cooling: " Daniel Lezcano
2021-03-12 18:05   ` Lukasz Luba
2021-03-12 17:03 ` [PATCH v2 4/5] thermal/drivers/cpuidle_cooling: " Daniel Lezcano
2021-03-15  3:07   ` Viresh Kumar
2021-03-15  3:10     ` Daniel Lezcano
2021-03-12 17:03 ` [PATCH v2 5/5] thermal/drivers/cpufreq_cooling: Remove unused list Daniel Lezcano
2021-03-12 17:19   ` Lukasz Luba
2021-03-12 18:49 ` [PATCH v2 1/5] thermal/drivers/core: Use a char pointer for the cooling device name Lukasz Luba
2021-03-12 21:01   ` Daniel Lezcano [this message]
2021-03-15  9:40     ` Lukasz Luba
2021-03-15  9:58       ` Lukasz Luba
2021-03-14  9:53 ` Ido Schimmel
2021-03-14 10:48   ` Daniel Lezcano

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=f51fcec0-1483-cecb-d984-591097c324ca@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=davem@davemloft.net \
    --cc=idosch@nvidia.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=rui.zhang@intel.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

all inboxes | Powered by JetHome®