mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Mehdi Djait <mehdi.djait@linux.intel.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	tomi.valkeinen@ideasonboard.com, jacopo.mondi@ideasonboard.com,
	hverkuil@xs4all.nl, kieran.bingham@ideasonboard.com,
	naush@raspberrypi.com, mchehab@kernel.org, hdegoede@redhat.com,
	dave.stevenson@raspberrypi.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v3] media: v4l2-common: Add a helper for obtaining the clock producer
Date: Mon, 24 Mar 2025 07:37:57 +0000	[thread overview]
Message-ID: <Z-EL1Y9Fh_0Z8KBt@kekkonen.localdomain> (raw)
In-Reply-To: <ryzkubgzndeyufi2i4vuwmgaekyapol36oln237ki4m3fh32yl@mpr7g5woiqcf>

Hi Laurent, Mehdi,

On Fri, Mar 21, 2025 at 01:30:43PM +0100, Mehdi Djait wrote:
> Hi Laurent,
> 
> thank you for the review!
> 
> On Fri, Mar 21, 2025 at 12:11:24PM +0200, Laurent Pinchart wrote:
> > Hi Mehdi,
> > 
> > Thank you for the patch.
> > 
> > On Fri, Mar 21, 2025 at 10:38:14AM +0100, Mehdi Djait wrote:
> 
> SNIP
> 
> > > +
> > > +struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
> > > +{
> > > +	struct clk_hw *clk_hw;
> > > +	struct clk *clk;
> > > +	u32 rate;
> > > +	int ret;
> > > +
> > > +	clk = devm_clk_get_optional(dev, id);
> > > +	if (clk)
> > > +		return clk;
> > > +
> > > +#ifdef CONFIG_COMMON_CLK
> > 
> > This patch will cause warnings when CONFIG_COMMON_CLK is disabled. Could
> > you use
> > 
> > 	if (IS_REACHABLE(CONFIG_COMMON_CLK)) {
> > 		...
> > 	}
> > 
> > instead ? It will also ensure that all code gets compile-tested, even
> > when CONFIG_COMMON_CLK is disabled ?
> > 
> > If you want to minimize implementation, you could write
> > 
> > 	if (!IS_REACHABLE(CONFIG_COMMON_CLK))
> > 		return ERR_PTR(-ENOENT);
> > 
> > and keep the code below as-is.
> > 
> 
> this is indeed way better! I will change this in the v3

This would work at the moment if devm_clk_hw_register_fixed_rate() was
always available but it evaluates to __clk_hw_register_fixed_rate() that
depends on COMMON_CLK.

I think t he best option would be to add a stub for it for !COMMON_CLK
case. It may take some time to get that merged and into the media tree. C99
also allows declaring variables midst of a basic block so declaring rate
and clkhw later should address the warning.

> 
> > > +	if (!is_acpi_node(dev_fwnode(dev)))
> > > +		return ERR_PTR(-ENOENT);
> > > +
> > > +	ret = device_property_read_u32(dev, "clock-frequency", &rate);
> > > +	if (ret)
> > > +		return ERR_PTR(ret);
> > > +
> > > +	if (!id) {
> > > +		id = devm_kasprintf(dev, GFP_KERNEL, "clk-%s", dev_name(dev));
> > 
> > As far as I understand, the name doesn't need to stay valid after
> > devm_clk_hw_register_fixed_rate() returns. You can call kasprintf here,
> > and call kfree after devm_clk_hw_register_fixed_rate(). You could use
> > __free to manage the memory life time:
> > 
> > 	const char *clk_id __free(kfree) = NULL;
> > 
> > 	if (!id) {
> > 		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
> > 		if (!clk_id)
> > 			return ERR_PTR(-ENOMEM);
> > 		id = clk_id;
> > 	}
> > 
> 
> Ack.
> 

-- 
Kind regards,

Sakari Ailus

  reply	other threads:[~2025-03-24  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21  9:38 Mehdi Djait
2025-03-21 10:11 ` Laurent Pinchart
2025-03-21 12:30   ` Mehdi Djait
2025-03-24  7:37     ` Sakari Ailus [this message]
2025-04-16 16:31       ` Mehdi Djait

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=Z-EL1Y9Fh_0Z8KBt@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=hdegoede@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mehdi.djait@linux.intel.com \
    --cc=naush@raspberrypi.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    /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

all inboxes | Powered by JetHome®