Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp151086rdb; Fri, 5 Jan 2024 05:50:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpe/aTN4b/z/ckX7r2Sr+8a6pHzrAesXb2ndgJ4Yzrk1IKs9OSAdKlEUoiU6aipsM9Er9Y X-Received: by 2002:a05:6808:309d:b0:3bc:3ca9:87c8 with SMTP id bl29-20020a056808309d00b003bc3ca987c8mr27052oib.80.1704462656389; Fri, 05 Jan 2024 05:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704462656; cv=none; d=google.com; s=arc-20160816; b=uU/PgZSiZWX2xojzGUeXk1NF91AkilXiSW/9xpsEvrNi89rqfHPLBx4MeME0kVIIZD pcHbR7mIj49FSiyayfsNgjlJDEk6HlYLFaIQii4CCXgtU5GigkoQW24TO413p+UG3N+P A7FeDXx2Mv6qEJZP0favhw5+K2AqcSy1KBk6uMIN1SkYhNLJR9rhAFqnqXx/RiATOYpa wMsh5VpF86p23JAltJxReJT173NGaovx6GRf+v+M3wDW1eijFLlchOjeLranp0xZJXo1 EdESzmuUzy1SLVhdw2z/TEefYa829Y2R/N18LFgZEVW064eC+8N2sXR0F3YZHOgPLSzT PBeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=lI0aY5vn80S9gXjhRUwYbNSINF0K3AxL2pL6R4NKMyY=; fh=AmPVfYqIfQms85eXo+vHrjfJOtIp1HDAmu9QhetaQ4A=; b=AtG6Rs7SfT7HSDR8DNw6BPNqtGZtVIZ0Oo0xjJsMzsn/w/2zBQJG0uRtck762Vm+2O mN/AfpxRyebJDn33eQ6pedNxPS9PBlLi/bbZ+FF2yvk4AYNl1e0aWpr6UeDnMz+hU/nN S60ldt1/ZG5qi5qaFPrWJ7xOMSbYZTYPLZCOBAobSCS0dq6NoZQcJcUAlq+MzZ0tirAB 2+ZabNRe6bKRw0BvsgWC3zN8cgb2lrvU94ekhN2jCgvgCmjC/6sB6jIPQsQuxhVEfSJW hHXaBdu08nmYqkEGNWwlSHBaDErjITcDK7vV2QXq++OvTfadGTjSQ/SqRsb//K59j+mk /cog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17894-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17894-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a4-20020a0ce384000000b0067f9789bea1si1804000qvl.53.2024.01.05.05.50.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 05:50:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17894-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17894-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17894-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 244D61C22AA4 for ; Fri, 5 Jan 2024 13:50:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06A1E2D7B2; Fri, 5 Jan 2024 13:50:44 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F49B24A0F; Fri, 5 Jan 2024 13:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5962dd690d3so92366eaf.0; Fri, 05 Jan 2024 05:50:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704462641; x=1705067441; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lI0aY5vn80S9gXjhRUwYbNSINF0K3AxL2pL6R4NKMyY=; b=FCvNz/EDNJ8lcAjNqB/Om4BwTVn1b/gQh50FPJDBrWk8J3kk8dfPmj6TwNPJQ5YBex 5UB+zWE3Dk3t6JYKl91cRJcTZW0MWuKQeg1x2pXy58CCEsjnOKJee4rCP3tavo/uE4Sl PIrETspgXKaATZmOM+2XpVs/TtyQhUEpGd3unfC3dxjWKssTYbRr1NMot6oNkoJOe+fc zsBZNzsYbpg8QCX4TAmMSxjGSynI64LWOZknmCn9aScrQ+9OZ9mIeUSNTX/MGRugW+ie dq3wWsHb+12JKpfEO3SqvyoEF4ZXPBniOBomjHIG7T+Z+MkMXoMteKNzRczyoR5HZSt5 5gFw== X-Gm-Message-State: AOJu0YznI3oAXiPazC4HO/aJ8v+AUK+N5zcQ3QpqswHWff3PsindqMxZ Br8JLOK81c4bVMUjYiELbkRrSGZ65w3vIgIj/Pw= X-Received: by 2002:a4a:d813:0:b0:598:1e1a:c551 with SMTP id f19-20020a4ad813000000b005981e1ac551mr112709oov.1.1704462641256; Fri, 05 Jan 2024 05:50:41 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <4a3658efad8f6247ed8c477717dc2820b72319d0.1704462287.git.christophe.jaillet@wanadoo.fr> In-Reply-To: <4a3658efad8f6247ed8c477717dc2820b72319d0.1704462287.git.christophe.jaillet@wanadoo.fr> From: "Rafael J. Wysocki" Date: Fri, 5 Jan 2024 14:50:30 +0100 Message-ID: Subject: Re: [PATCH] thermal: core: Save a few bytes of memory when registering a cooling device To: Christophe JAILLET Cc: "Rafael J. Wysocki" , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 5, 2024 at 2:45=E2=80=AFPM Christophe JAILLET wrote: > > Some *thermal_cooling_device_register() calls pass a string literal as th= e > 'type' parameter. > > So kstrdup_const() can be used instead of kfree() to avoid a memory I guess you mean kstrdup()? > 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_cor= e.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 =3D 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 =3D ret; > id =3D ret; > > - cdev->type =3D kstrdup(type ? type : "", GFP_KERNEL); > + cdev->type =3D kstrdup_const(type ? type : "", GFP_KERNEL); > if (!cdev->type) { > ret =3D -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 >