Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp189192rdb; Fri, 5 Jan 2024 06:56:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHO+RA5o0XjjahK/pimM1VssLANSL0O264uJpEmyNWp3f+4fLE+2FAMZTFszxCRR6Uze4Q X-Received: by 2002:a17:903:40c7:b0:1d4:e20f:c4c3 with SMTP id t7-20020a17090340c700b001d4e20fc4c3mr2115822pld.54.1704466581959; Fri, 05 Jan 2024 06:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704466581; cv=none; d=google.com; s=arc-20160816; b=zRpPhelJadF0JYIQJf+h5mWH1vG6ES2zb7Y5Gi7oJyWAXlra427ZeMLMtuYiHLOPYv NQm+uGIOwIke482shmzeAINAhks4atCouWLQQjXIJFntaVtJiykTPsvoGdCNYL8/Flfl AJdJ9BmrLERtJgtye0b8ll5ZseSHr2bhaEeH9kuXx9vfaWNZoQywIoVyfeILWwzjEXIR x7jF6paerF+Cz3LeRXwu5Ft5TvVn82TTADWsACcU0+SesB6F2ofOiWIV80iv9B3nlS3l wbky+gPv6WSZf+3AQpgLt4JJ4lpJxObXDPvk21+SmKYKZZiGZP1Le54nLCE/0gBgIooC weYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=3o+5IuQI3KZqIsQuHVkAVYAXMFpoFfomYAL99cJxMGI=; fh=qtcHjT2rTS6xwNdk4HtTsKIfVe2WYyi0Ee4p/fZ4laI=; b=e7+RxkbIm2n4NLi9Ce1Esiv/E815bknMKAmmALZ16K6VyMX20ImqB0CHzw7Jo/VYnV IqsMdcE4O0WK7XZEAKRJxY7N+z5AHQC8O1zuLTgfyf2JIpu2WOMo6tn8Vtz3I7mRUEuK Dd/UEQHcswNBKFxKA0ue+hiULc9kMl9B6bOKICAmdOaXn8ynhUJDDD8tgKGQx15Mzk+G zvKAngvYui/A47F6GBe0YMVTBe4N6hhUKlnuMPZBeiLE/zqWtgKZzzCHIc3SDK5SSePq ECWp6q8EVnGmMYcyOgA3qnkyboTqy+1jpBRXuOWvavxwZ6/gxWNJ72ViBnajNxjMi+BF nN0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=sgpU6O11; spf=pass (google.com: domain of linux-kernel+bounces-17975-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17975-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h2-20020a170902f54200b001d4e1d45a73si1400161plf.99.2024.01.05.06.56.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 06:56:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17975-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=sgpU6O11; spf=pass (google.com: domain of linux-kernel+bounces-17975-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17975-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 037DD284BE0 for ; Fri, 5 Jan 2024 14:55:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BBD12E640; Fri, 5 Jan 2024 14:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="sgpU6O11" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.smtpout.orange.fr (smtp-19.smtpout.orange.fr [80.12.242.19]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 066E02E631; Fri, 5 Jan 2024 14:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from [192.168.1.18] ([92.140.202.140]) by smtp.orange.fr with ESMTPA id LlU8rZXOax8edLlU8rWP3j; Fri, 05 Jan 2024 15:47:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1704466066; bh=3o+5IuQI3KZqIsQuHVkAVYAXMFpoFfomYAL99cJxMGI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=sgpU6O11WbmPfG4vpUH2O7BN1pofyUbOrstaUMQg0d2e0uzP2AewwyzIk/YctiQZO CWGCK7hoX12xjrEAgBUI4ER5Ayb44ki9D7O8crIiCjzpQgnROgUMcIt1DNqlNyCEor AIMKuqcpZEvg6kJcg/vxxLgNOvxjnRLbCYUALcmplkO0gGieZ6WOfraYiqJ3TcEtgF vTFfCoVYx7KV+kxZpGe9Qdf9ISAqdEIMPoPGLzjitMYIvdoeD9RnTeetFELFUoiDJy 6NC8CmhTBq8lxs1LPup6OmvL+8i8GwzaRCpUYUaAWJ8VPwrhsPWlSj33xz8dBLqbGn y8i+4UGB10THw== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 05 Jan 2024 15:47:46 +0100 X-ME-IP: 92.140.202.140 Message-ID: Date: Fri, 5 Jan 2024 15:47:43 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] thermal: core: Save a few bytes of memory when registering a cooling device Content-Language: fr To: "Rafael J. Wysocki" Cc: Daniel Lezcano , Zhang Rui , Lukasz Luba , alexis.lothore@bootlin.com, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-pm@vger.kernel.org References: <4a3658efad8f6247ed8c477717dc2820b72319d0.1704462287.git.christophe.jaillet@wanadoo.fr> From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 05/01/2024 à 14:50, Rafael J. Wysocki a écrit : > On Fri, Jan 5, 2024 at 2:45 PM Christophe JAILLET > wrote: >> >> Some *thermal_cooling_device_register() calls pass a string literal as the >> 'type' parameter. >> >> So kstrdup_const() can be used instead of kfree() to avoid a memory > > I guess you mean kstrdup()? Sure. Stupid cut'n'paste typo. Thx for catching it. Should I resend, or can it be fixed if/when the patch is applied? CJ > >> allocation in such cases. >> >> Signed-off-by: Christophe JAILLET >> --- >> drivers/thermal/thermal_core.c | 6 +++--- >> include/linux/thermal.h | 2 +- >> 2 files changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c >> index fa88d8707241..d21225ddbf10 100644 >> --- a/drivers/thermal/thermal_core.c >> +++ b/drivers/thermal/thermal_core.c >> @@ -846,7 +846,7 @@ static void thermal_release(struct device *dev) >> sizeof("cooling_device") - 1)) { >> cdev = to_cooling_device(dev); >> thermal_cooling_device_destroy_sysfs(cdev); >> - kfree(cdev->type); >> + kfree_const(cdev->type); >> ida_free(&thermal_cdev_ida, cdev->id); >> kfree(cdev); >> } >> @@ -918,7 +918,7 @@ __thermal_cooling_device_register(struct device_node *np, >> cdev->id = ret; >> id = ret; >> >> - cdev->type = kstrdup(type ? type : "", GFP_KERNEL); >> + cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL); >> if (!cdev->type) { >> ret = -ENOMEM; >> goto out_ida_remove; >> @@ -969,7 +969,7 @@ __thermal_cooling_device_register(struct device_node *np, >> out_cooling_dev: >> thermal_cooling_device_destroy_sysfs(cdev); >> out_cdev_type: >> - kfree(cdev->type); >> + kfree_const(cdev->type); >> out_ida_remove: >> ida_free(&thermal_cdev_ida, id); >> out_kfree_cdev: >> diff --git a/include/linux/thermal.h b/include/linux/thermal.h >> index bf84595a4e86..052c72c0fa17 100644 >> --- a/include/linux/thermal.h >> +++ b/include/linux/thermal.h >> @@ -102,7 +102,7 @@ struct thermal_cooling_device_ops { >> >> struct thermal_cooling_device { >> int id; >> - char *type; >> + const char *type; >> unsigned long max_state; >> struct device device; >> struct device_node *np; >> -- >> 2.34.1 >> > >