From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1244BC433E0 for ; Mon, 15 Mar 2021 09:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D778C64EAE for ; Mon, 15 Mar 2021 09:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbhCOJke (ORCPT ); Mon, 15 Mar 2021 05:40:34 -0400 Received: from foss.arm.com ([217.140.110.172]:55894 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbhCOJkJ (ORCPT ); Mon, 15 Mar 2021 05:40:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 37F691FB; Mon, 15 Mar 2021 02:40:09 -0700 (PDT) Received: from [10.57.12.51] (unknown [10.57.12.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6CAE3F70D; Mon, 15 Mar 2021 02:40:06 -0700 (PDT) Subject: Re: [PATCH v2 1/5] thermal/drivers/core: Use a char pointer for the cooling device name To: Daniel Lezcano Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jiri Pirko , Ido Schimmel , "David S. Miller" , Jakub Kicinski , Zhang Rui , Amit Kucheria , "open list:MELLANOX ETHERNET SWITCH DRIVERS" References: <20210312170316.3138-1-daniel.lezcano@linaro.org> <18fdc11b-abda-25d9-582f-de2f9dfa2feb@arm.com> From: Lukasz Luba Message-ID: <1aada78d-06f1-4ccd-cf81-7c2e8f5fe747@arm.com> Date: Mon, 15 Mar 2021 09:40:06 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 3/12/21 9:01 PM, Daniel Lezcano wrote: > 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 >>> --- >>>   .../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 ? Yes, we have to remove 'ida' and you jump to that label: goto out_ida_remove; but under that label, there is no 'put_device()'. We could have here, before the 'goto', a simple kfree, which should be safe, since we haven't called the device_register() yet. Something like: --------8<------------------------------ cdev->type = kstrdup(type ? type : "", GFP_KERNEL); if (!cdev->type) { ret = -ENOMEM; kfree(cdev); goto out_ida_remove; } -------->8------------------------------ > >> Other than that, LGTM >> >> Reviewed-by: Lukasz Luba >> >> Regards, >> Lukasz > >