From: Jani Nikula <jani.nikula@linux.intel.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Tvrtko Ursulin <tursulin@ursulin.net>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/backlight: Remove a useless kstrdup_const()
Date: Mon, 30 Sep 2024 10:48:40 +0300 [thread overview]
Message-ID: <875xqdy42v.fsf@intel.com> (raw)
In-Reply-To: <3b3d3af8739e3016f3f80df0aa85b3c06230a385.1727533674.git.christophe.jaillet@wanadoo.fr>
On Sat, 28 Sep 2024, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> "name" is allocated and freed in intel_backlight_device_register().
> The initial allocation just duplicates "intel_backlight".
>
> Later, if a device with this name has already been registered, another
> dynamically generated one is allocated using kasprintf().
>
> So at the end of the function, when "name" is freed, it can point either to
> the initial static literal "intel_backlight" or to the kasprintf()'ed one.
>
> So kfree_const() is used.
>
> However, when built as a module, kstrdup_const() and kfree_const() don't
> work as one would expect and are just plain kstrdup() and kfree().
>
>
> Slightly change the logic and introduce a new variable to hold the
> address returned by kasprintf() should it be used.
>
> This saves a memory allocation/free and avoids these _const functions,
> which names can be confusing when used with code built as module.
Okay, I'd rather revert your earlier commit 379b63e7e682
("drm/i915/display: Save a few bytes of memory in
intel_backlight_device_register()") than add this.
The code simplicity is much more important than saving a few bytes.
BR,
Jani.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
>
> For the records, this patch is a clean-up effort related to discussions at:
> - https://lore.kernel.org/all/ZvHurCYlCoi1ZTCX@skv.local/
> - https://lore.kernel.org/all/20240924050937.697118-1-senozhatsky@chromium.org/
> ---
> drivers/gpu/drm/i915/display/intel_backlight.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_backlight.c b/drivers/gpu/drm/i915/display/intel_backlight.c
> index 9e05745d797d..bf7686aa044f 100644
> --- a/drivers/gpu/drm/i915/display/intel_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
> @@ -914,9 +914,9 @@ int intel_backlight_device_register(struct intel_connector *connector)
> {
> struct drm_i915_private *i915 = to_i915(connector->base.dev);
> struct intel_panel *panel = &connector->panel;
> + const char *name, *new_name = NULL;
> struct backlight_properties props;
> struct backlight_device *bd;
> - const char *name;
> int ret = 0;
>
> if (WARN_ON(panel->backlight.device))
> @@ -949,10 +949,7 @@ int intel_backlight_device_register(struct intel_connector *connector)
> else
> props.power = BACKLIGHT_POWER_OFF;
>
> - name = kstrdup_const("intel_backlight", GFP_KERNEL);
> - if (!name)
> - return -ENOMEM;
> -
> + name = "intel_backlight";
> bd = backlight_device_get_by_name(name);
> if (bd) {
> put_device(&bd->dev);
> @@ -963,11 +960,11 @@ int intel_backlight_device_register(struct intel_connector *connector)
> * compatibility. Use unique names for subsequent backlight devices as a
> * fallback when the default name already exists.
> */
> - kfree_const(name);
> - name = kasprintf(GFP_KERNEL, "card%d-%s-backlight",
> - i915->drm.primary->index, connector->base.name);
> - if (!name)
> + new_name = kasprintf(GFP_KERNEL, "card%d-%s-backlight",
> + i915->drm.primary->index, connector->base.name);
> + if (!new_name)
> return -ENOMEM;
> + name = new_name;
> }
> bd = backlight_device_register(name, connector->base.kdev, connector,
> &intel_backlight_device_ops, &props);
> @@ -987,7 +984,7 @@ int intel_backlight_device_register(struct intel_connector *connector)
> connector->base.base.id, connector->base.name, name);
>
> out:
> - kfree_const(name);
> + kfree(new_name);
>
> return ret;
> }
--
Jani Nikula, Intel
next prev parent reply other threads:[~2024-09-30 7:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-28 14:28 [PATCH] drm/i915/backlight: Remove a useless kstrdup_const() Christophe JAILLET
2024-09-30 7:48 ` Jani Nikula [this message]
2024-10-01 18:34 ` Christophe JAILLET
2024-10-02 11:51 ` Jani Nikula
2024-10-02 16:43 ` Christophe JAILLET
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=875xqdy42v.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=tursulin@ursulin.net \
/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;
as well as URLs for NNTP newsgroup(s).