linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@roeck-us.net (Guenter Roeck)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
Date: Wed, 11 Jan 2017 09:28:37 -0800	[thread overview]
Message-ID: <20170111172837.GA22289@roeck-us.net> (raw)
In-Reply-To: <20170111143917.hedhyfu6m5dopag7@pengutronix.de>

On Wed, Jan 11, 2017 at 03:39:17PM +0100, Uwe Kleine-K?nig wrote:
> On Wed, Jan 11, 2017 at 01:31:47PM +0100, Marc Gonzalez wrote:
> > On 11/01/2017 11:52, Guenter Roeck wrote:
> > 
> > > On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> > > 
> > >>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
> > >>>  	err = clk_prepare_enable(dev->clk);
> > >>>  	if (err)
> > >>>  		return err;
> > >>> +	err = devm_add_action_or_reset(&pdev->dev,
> > >>> +				       (void(*)(void *))clk_disable_unprepare,
> > >>> +				       dev->clk);
> > >>> +	if (err)
> > >>> +		return err;
> 
> This looks wrong. There is no clk_unprepare_disable when
> devm_add_action_or_reset fails.
> 
That is what the _or_reset part of devm_add_action_or_reset() is for.

> > >>
> > >> Hello Guenter,
> > >>
> > >> I would rather avoid the function pointer cast.
> > >> How about defining an auxiliary function for the cleanup action?
> > >>
> > >> clk_disable_unprepare() is static inline, so gcc will have to
> > >> define an auxiliary function either way. What do you think?
> > > 
> > > Not really. It would just make it more complicated to replace the
> > > call with devm_clk_prepare_enable(), should it ever find its way
> > > into the light of day.
> > 
> > More complicated, because the cleanup function will have to be deleted later?
> > The compiler will warn if someone forgets to do that.
> > 
> > In my opinion, it's not a good idea to rely on the fact that casting
> > void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
> > on most platforms. (It has undefined behavior, strictly speaking.)
> 
> I would expect it to work on all (Linux) platforms. Anyhow, I wonder if
> there couldn't be found a better solution.
> 
> If in the end it looks like the following that would be good I think:
> 
> 	clk = devm_clk_get(...);
> 	if (IS_ERR(clk))
> 		...
> 
> 	ret = devm_clk_prepare_enable(clk)
> 	if (ret)
> 		return ret;
> 
Yes, Dmitry tried to introduce devm_clk_prepare_enable() some 5 years ago,
but the effort stalled.

My take is that it will be easy to write another coccinelle script to convert
to devm_clk_prepare_enable() once that is available, but I didn't see the point
of waiting for that, especially since it may never happen.

Guenter

  parent reply	other threads:[~2017-01-11 17:28 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1484091325-9199-1-git-send-email-linux@roeck-us.net>
2017-01-10 23:34 ` [PATCH 05/62] watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-14  6:27   ` Eric Anholt
2017-01-10 23:34 ` [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11 15:48   ` Linus Walleij
2017-01-10 23:34 ` [PATCH 16/62] watchdog: digicolor_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-12 11:47   ` Baruch Siach
2017-01-10 23:34 ` [PATCH 27/62] watchdog: lpc18xx_wdt: " Guenter Roeck
     [not found] ` <1484095516-12720-1-git-send-email-linux@roeck-us.net>
2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: " Guenter Roeck
2017-01-11  8:42     ` Neil Armstrong
2017-01-11 18:44     ` Kevin Hilman
2017-01-11  0:44   ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
2017-01-11 18:45     ` Kevin Hilman
2017-01-11  0:44   ` [PATCH 37/62] watchdog: mtk_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 39/62] watchdog: of_xilinx_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 44/62] watchdog: pnx4008_wdt: " Guenter Roeck
2017-01-12  0:13     ` Vladimir Zapolskiy
2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  2:09   ` [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  2:09   ` [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11 12:15     ` Maxime Ripard
2017-01-11  2:09   ` [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  9:07     ` Marc Gonzalez
2017-01-11 10:52       ` Guenter Roeck
2017-01-11 12:31         ` Marc Gonzalez
2017-01-11 14:25           ` Guenter Roeck
2017-01-11 14:43             ` Måns Rullgård
2017-01-11 15:28             ` Marc Gonzalez
2017-01-11 17:51               ` Guenter Roeck
2017-01-12  9:44                 ` Marc Gonzalez
2017-01-12  9:57                   ` Uwe Kleine-König
2017-01-12 11:24                   ` Måns Rullgård
2017-01-12 12:15                     ` Marc Gonzalez
2017-01-11 14:39           ` Uwe Kleine-König
2017-01-11 14:50             ` Vladimir Zapolskiy
2017-01-11 17:28             ` Guenter Roeck [this message]
2017-01-13  5:17             ` Guenter Roeck
2017-01-12  0:12         ` Andy Shevchenko
2017-01-12  1:29           ` Guenter Roeck

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=20170111172837.GA22289@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).