lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0946e8ae-e829-807f-2e56-a27c67da7073@roeck-us.net>
Date:   Wed, 10 Apr 2019 05:09:17 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Michal Simek <michal.simek@...inx.com>,
        Wim Van Sebroeck <wim@...ux-watchdog.org>
Cc:     linux-watchdog@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device
 managed functions and other improvements

On 4/9/19 11:38 PM, Michal Simek wrote:
> On 09. 04. 19 19:23, Guenter Roeck wrote:
>> Use device managed functions to simplify error handling, reduce
>> source code size, improve readability, and reduce the likelyhood of bugs.
>> Other improvements as listed below.
>>
>> The conversion was done automatically with coccinelle using the
>> following semantic patches. The semantic patches and the scripts
>> used to generate this commit log are available at
>> https://github.com/groeck/coccinelle-patches
>>
>> - Drop assignments to otherwise unused variables
>> - Drop empty remove function
>> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
>> - Introduce local variable 'struct device *dev' and use it instead of
>>    dereferencing it repeatedly
>> - Use devm_watchdog_register_driver() to register watchdog device
>>
>> Cc: Michal Simek <michal.simek@...inx.com>
>> Signed-off-by: Guenter Roeck <linux@...ck-us.net>
>> ---
>>   drivers/watchdog/of_xilinx_wdt.c | 58 ++++++++++++++++++----------------------
>>   1 file changed, 26 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
>> index 5c977164b3e5..03786992b701 100644
>> --- a/drivers/watchdog/of_xilinx_wdt.c
>> +++ b/drivers/watchdog/of_xilinx_wdt.c
>> @@ -151,41 +151,46 @@ static u32 xwdt_selftest(struct xwdt_device *xdev)
>>   		return XWT_TIMER_FAILED;
>>   }
>>   
>> +static void xwdt_clk_disable_unprepare(void *data)
>> +{
>> +	clk_disable_unprepare(data);
>> +}
>> +
>>   static int xwdt_probe(struct platform_device *pdev)
>>   {
>> +	struct device *dev = &pdev->dev;
>>   	int rc;
>>   	u32 pfreq = 0, enable_once = 0;
>>   	struct xwdt_device *xdev;
>>   	struct watchdog_device *xilinx_wdt_wdd;
>>   
>> -	xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
>> +	xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
>>   	if (!xdev)
>>   		return -ENOMEM;
>>   
>>   	xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
>>   	xilinx_wdt_wdd->info = &xilinx_wdt_ident;
>>   	xilinx_wdt_wdd->ops = &xilinx_wdt_ops;
>> -	xilinx_wdt_wdd->parent = &pdev->dev;
>> +	xilinx_wdt_wdd->parent = dev;
>>   
>>   	xdev->base = devm_platform_ioremap_resource(pdev, 0);
>>   	if (IS_ERR(xdev->base))
>>   		return PTR_ERR(xdev->base);
>>   
>> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
>> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval",
>>   				  &xdev->wdt_interval);
>>   	if (rc)
>> -		dev_warn(&pdev->dev,
>> -			 "Parameter \"xlnx,wdt-interval\" not found\n");
>> +		dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n");
>>   
>> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once",
>> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once",
>>   				  &enable_once);
>>   	if (rc)
>> -		dev_warn(&pdev->dev,
>> +		dev_warn(dev,
>>   			 "Parameter \"xlnx,wdt-enable-once\" not found\n");
>>   
>>   	watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
>>   
>> -	xdev->clk = devm_clk_get(&pdev->dev, NULL);
>> +	xdev->clk = devm_clk_get(dev, NULL);
>>   	if (IS_ERR(xdev->clk)) {
>>   		if (PTR_ERR(xdev->clk) != -ENOENT)
>>   			return PTR_ERR(xdev->clk);
>> @@ -196,10 +201,10 @@ static int xwdt_probe(struct platform_device *pdev)
>>   		 */
>>   		xdev->clk = NULL;
>>   
>> -		rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
>> +		rc = of_property_read_u32(dev->of_node, "clock-frequency",
>>   					  &pfreq);
>>   		if (rc)
>> -			dev_warn(&pdev->dev,
>> +			dev_warn(dev,
>>   				 "The watchdog clock freq cannot be obtained\n");
>>   	} else {
>>   		pfreq = clk_get_rate(xdev->clk);
>> @@ -218,44 +223,34 @@ static int xwdt_probe(struct platform_device *pdev)
>>   
>>   	rc = clk_prepare_enable(xdev->clk);
>>   	if (rc) {
>> -		dev_err(&pdev->dev, "unable to enable clock\n");
>> +		dev_err(dev, "unable to enable clock\n");
>>   		return rc;
>>   	}
>> +	rc = devm_add_action_or_reset(dev, xwdt_clk_disable_unprepare,
>> +				      xdev->clk);
>> +	if (rc)
>> +		return rc;
>>   
>>   	rc = xwdt_selftest(xdev);
>>   	if (rc == XWT_TIMER_FAILED) {
>> -		dev_err(&pdev->dev, "SelfTest routine error\n");
>> -		goto err_clk_disable;
>> +		dev_err(dev, "SelfTest routine error\n");
>> +		return rc;
>>   	}
>>   
>> -	rc = watchdog_register_device(xilinx_wdt_wdd);
>> +	rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd);
>>   	if (rc) {
>> -		dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
>> -		goto err_clk_disable;
>> +		dev_err(dev, "Cannot register watchdog (err=%d)\n", rc);
>> +		return rc;
>>   	}
>>   
>>   	clk_disable(xdev->clk);
>>   
>> -	dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
>> +	dev_info(dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
>>   		 xdev->base, xilinx_wdt_wdd->timeout);
>>   
>>   	platform_set_drvdata(pdev, xdev);
>>   
>>   	return 0;
>> -err_clk_disable:
>> -	clk_disable_unprepare(xdev->clk);
>> -
>> -	return rc;
>> -}
>> -
>> -static int xwdt_remove(struct platform_device *pdev)
>> -{
>> -	struct xwdt_device *xdev = platform_get_drvdata(pdev);
>> -
>> -	watchdog_unregister_device(&xdev->xilinx_wdt_wdd);
>> -	clk_disable_unprepare(xdev->clk);
>> -
>> -	return 0;
>>   }
>>   
>>   /**
>> @@ -303,7 +298,6 @@ MODULE_DEVICE_TABLE(of, xwdt_of_match);
>>   
>>   static struct platform_driver xwdt_driver = {
>>   	.probe       = xwdt_probe,
>> -	.remove      = xwdt_remove,
>>   	.driver = {
>>   		.name  = WATCHDOG_NAME,
>>   		.of_match_table = xwdt_of_match,
>>
> 
> Looks good to me. I would prefer to do it via 3 patches but I will let
> Wim to comment.
> 

I could do that, but the total series is already more than 60 patches.
Splitting them up would mean hundreds of patches.

> Acked-by: Michal Simek <michal.simek@...inx.com>
> 

Thanks,
Guenter

Powered by blists - more mailing lists