Linux Media Controller development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Andy Shevchenko <andy@kernel.org>,
	Dan Scally <djrscally@gmail.com>,
	 Alan Stern <stern@rowland.harvard.edu>,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hao Yao <hao.yao@intel.com>,  Bingbu Cao <bingbu.cao@intel.com>,
	Duane <duanek@chorus.net>,
	 platform-driver-x86@vger.kernel.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH v4 1/9] platform/x86: int3472: Add skl_int3472_register_clock() helper
Date: Thu, 17 Apr 2025 15:59:15 +0300 (EEST)	[thread overview]
Message-ID: <252a5c3a-9ea1-a02b-627e-1937277e9c15@linux.intel.com> (raw)
In-Reply-To: <20250417111337.38142-2-hdegoede@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3853 bytes --]

On Thu, 17 Apr 2025, Hans de Goede wrote:

> skl_int3472_register_dsm_clock() and skl_int3472_register_gpio_clock() are
> 80% the same code. Factor out the common code into a new
> skl_int3472_register_clock() helper.
> 
> Reviewed-by: Andy Shevchenko <andy@kernel.org>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  .../x86/intel/int3472/clk_and_regulator.c     | 57 +++++--------------
>  1 file changed, 13 insertions(+), 44 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/int3472/clk_and_regulator.c b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
> index 16e36ac0a7b4..837990af24fe 100644
> --- a/drivers/platform/x86/intel/int3472/clk_and_regulator.c
> +++ b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
> @@ -118,7 +118,7 @@ static const struct clk_ops skl_int3472_clock_ops = {
>  	.recalc_rate = skl_int3472_clk_recalc_rate,
>  };
>  
> -int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
> +static int skl_int3472_register_clock(struct int3472_discrete_device *int3472)
>  {
>  	struct acpi_device *adev = int3472->adev;
>  	struct clk_init_data init = {
> @@ -127,12 +127,6 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
>  	};
>  	int ret;
>  
> -	if (int3472->clock.cl)
> -		return 0; /* A GPIO controlled clk has already been registered */
> -
> -	if (!acpi_check_dsm(adev->handle, &img_clk_guid, 0, BIT(1)))
> -		return 0; /* DSM clock control is not available */
> -
>  	init.name = kasprintf(GFP_KERNEL, "%s-clk", acpi_dev_name(adev));
>  	if (!init.name)
>  		return -ENOMEM;
> @@ -161,51 +155,26 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
>  	return ret;
>  }
>  
> +int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
> +{
> +	if (int3472->clock.cl)
> +		return 0; /* A GPIO controlled clk has already been registered */
> +
> +	if (!acpi_check_dsm(int3472->adev->handle, &img_clk_guid, 0, BIT(1)))
> +		return 0; /* DSM clock control is not available */
> +
> +	return skl_int3472_register_clock(int3472);
> +}
> +
>  int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
>  				    struct gpio_desc *gpio)
>  {
> -	struct clk_init_data init = {
> -		.ops = &skl_int3472_clock_ops,
> -		.flags = CLK_GET_RATE_NOCACHE,
> -	};
> -	int ret;
> -
>  	if (int3472->clock.cl)
>  		return -EBUSY;
>  
>  	int3472->clock.ena_gpio = gpio;
>  
> -	init.name = kasprintf(GFP_KERNEL, "%s-clk",
> -			      acpi_dev_name(int3472->adev));
> -	if (!init.name)
> -		return -ENOMEM;
> -
> -	int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472);
> -
> -	int3472->clock.clk_hw.init = &init;
> -	int3472->clock.clk = clk_register(&int3472->adev->dev,
> -					  &int3472->clock.clk_hw);
> -	if (IS_ERR(int3472->clock.clk)) {
> -		ret = PTR_ERR(int3472->clock.clk);
> -		goto out_free_init_name;
> -	}
> -
> -	int3472->clock.cl = clkdev_create(int3472->clock.clk, NULL,
> -					  int3472->sensor_name);
> -	if (!int3472->clock.cl) {
> -		ret = -ENOMEM;
> -		goto err_unregister_clk;
> -	}
> -
> -	kfree(init.name);
> -	return 0;
> -
> -err_unregister_clk:
> -	clk_unregister(int3472->clock.clk);
> -out_free_init_name:
> -	kfree(init.name);
> -
> -	return ret;
> +	return skl_int3472_register_clock(int3472);
>  }
>  
>  void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

To get rid of a few kfree()s, one could consider this additional cleanup 
as a separate patch:

	char *name __free(kfree) = kasprintf(...);
	if (!name)
		return -ENOMEM;

	init.name = name;

(FYI, I won't have time to go through rest of the patch in this series 
today.)

-- 
 i.

  reply	other threads:[~2025-04-17 12:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17 11:13 [PATCH v4 0/9] platform/x86: int3472: Add handshake pin support Hans de Goede
2025-04-17 11:13 ` [PATCH v4 1/9] platform/x86: int3472: Add skl_int3472_register_clock() helper Hans de Goede
2025-04-17 12:59   ` Ilpo Järvinen [this message]
2025-04-17 11:13 ` [PATCH v4 2/9] platform/x86: int3472: Stop setting a supply-name for GPIO regulators Hans de Goede
2025-04-17 11:13 ` [PATCH v4 3/9] platform/x86: int3472: Drop unused gpio field from struct int3472_gpio_regulator Hans de Goede
2025-04-17 11:13 ` [PATCH v4 4/9] platform/x86: int3472: Rework AVDD second sensor quirk handling Hans de Goede
2025-04-17 11:13 ` [PATCH v4 5/9] platform/x86: int3472: Make regulator supply name configurable Hans de Goede
2025-04-17 16:25   ` Andy Shevchenko
2025-04-23 13:58     ` Ilpo Järvinen
2025-04-23 15:38       ` Andy Shevchenko
2025-04-24 14:06   ` Ilpo Järvinen
2025-04-25  9:06     ` Hans de Goede
2025-04-17 11:13 ` [PATCH v4 6/9] platform/x86: int3472: Avoid GPIO regulator spikes Hans de Goede
2025-04-17 11:13 ` [PATCH v4 7/9] platform/x86: int3472: Prepare for registering more than 1 GPIO regulator Hans de Goede
2025-04-17 11:13 ` [PATCH v4 8/9] platform/x86: int3472: Add handshake pin support Hans de Goede
2025-04-17 11:13 ` [PATCH v4 9/9] platform/x86: int3472: Debug log when remapping pins Hans de Goede
2025-04-18 15:47 ` [PATCH v4 0/9] platform/x86: int3472: Add handshake pin support David Heidelberg
2025-04-23  9:46 ` Sakari Ailus

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=252a5c3a-9ea1-a02b-627e-1937277e9c15@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=bingbu.cao@intel.com \
    --cc=djrscally@gmail.com \
    --cc=duanek@chorus.net \
    --cc=hao.yao@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-media@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    /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