From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761888AbdAKOZo (ORCPT ); Wed, 11 Jan 2017 09:25:44 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:49836 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752814AbdAKOZn (ORCPT ); Wed, 11 Jan 2017 09:25:43 -0500 Subject: Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions To: Marc Gonzalez References: <1484091325-9199-1-git-send-email-linux@roeck-us.net> <1484100561-17638-1-git-send-email-linux@roeck-us.net> <1484100561-17638-5-git-send-email-linux@roeck-us.net> <94c4d5c0-f639-eab1-6706-335977690e88@roeck-us.net> Cc: Wim Van Sebroeck , linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mans Rullgard , Thibaud Cornic , Mark Rutland , Uwe Kleine-Konig , Arnd Bergmann From: Guenter Roeck Message-ID: Date: Wed, 11 Jan 2017 06:25:35 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/11/2017 04:31 AM, 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; >>> >>> 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 do hear that you object to this code. However, I must admit that you completely lost me here. It is a cast from one function pointer to another, passed as argument to another function, with a secondary cast of its argument from a typed pointer to a void pointer. I don't think C permits for "undefined behavior, strictly speaking". Besides, that same mechanism is already used elsewhere, which is how I got the idea. Are you claiming that there are situations where it won't work ? > Do you really dislike the portable solution I suggested? :-( > It is not more portable than the above. It is more expensive and adds more code. Thanks, Guenter