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: <20210725220320.GE3578169@roeck-us.net>
Date:   Sun, 25 Jul 2021 15:03:20 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Ahmad Fatoum <a.fatoum@...gutronix.de>
Cc:     Wim Van Sebroeck <wim@...ux-watchdog.org>,
        linux-watchdog@...r.kernel.org, kernel@...gutronix.de,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 4/5] watchdog: f71808e_wdt: refactor to platform
 device/driver pair

On Thu, Jul 22, 2021 at 12:14:43PM +0200, Ahmad Fatoum wrote:
> Driver so far wasn't ported to the driver model and registered
> the watchdog device out of the init after probing the I/O ports
> for a watchdog with correct vendor and device revision.
> 
> Keep the device detection part at init time, but move watchdog
> registration to a platform driver probe function.
> 
> Suggested-by: Guenter Roeck <linux@...ck-us.net>
> Signed-off-by: Ahmad Fatoum <a.fatoum@...gutronix.de>

Reviewed-by: Guenter Roeck <linux@...ck-us.net>

> ---
>  drivers/watchdog/f71808e_wdt.c | 42 +++++++++++++++++++++++++++++++----
>  1 file changed, 38 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
> index efc6981d9a9b..d4cae73da002 100644
> --- a/drivers/watchdog/f71808e_wdt.c
> +++ b/drivers/watchdog/f71808e_wdt.c
> @@ -13,6 +13,7 @@
>  #include <linux/io.h>
>  #include <linux/ioport.h>
>  #include <linux/module.h>
> +#include <linux/platform_device.h>
>  #include <linux/watchdog.h>
>  
>  #define DRVNAME "f71808e_wdt"
> @@ -432,10 +433,18 @@ static const struct watchdog_ops fintek_wdt_ops = {
>  	.set_timeout = fintek_wdt_set_timeout,
>  };
>  
> -static int __init watchdog_init(int sioaddr)
> +static int fintek_wdt_probe(struct platform_device *pdev)
>  {
>  	struct watchdog_device *wdd;
>  	int wdt_conf, err = 0;
> +	struct resource *res;
> +	int sioaddr;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> +	if (!res)
> +		return -ENXIO;
> +
> +	sioaddr = res->start;
>  
>  	watchdog.sioaddr = sioaddr;
>  	watchdog.ident.options = WDIOF_SETTIMEOUT
> @@ -468,6 +477,7 @@ static int __init watchdog_init(int sioaddr)
>  
>  	superio_exit(sioaddr);
>  
> +	wdd->parent		= &pdev->dev;
>  	wdd->info               = &watchdog.ident;
>  	wdd->ops                = &fintek_wdt_ops;
>  	wdd->min_timeout        = 1;
> @@ -488,7 +498,7 @@ static int __init watchdog_init(int sioaddr)
>  	fintek_wdt_set_timeout(wdd, timeout);
>  	fintek_wdt_set_pulse_width(pulse_width);
>  
> -	return watchdog_register_device(wdd);
> +	return devm_watchdog_register_device(&pdev->dev, wdd);
>  }
>  
>  static int __init fintek_wdt_find(int sioaddr)
> @@ -554,9 +564,19 @@ static int __init fintek_wdt_find(int sioaddr)
>  	return err;
>  }
>  
> +static struct platform_driver fintek_wdt_driver = {
> +	.probe          = fintek_wdt_probe,
> +	.driver         = {
> +		.name   = DRVNAME,
> +	},
> +};
> +
> +static struct platform_device *fintek_wdt_pdev;
> +
>  static int __init fintek_wdt_init(void)
>  {
>  	static const unsigned short addrs[] = { 0x2e, 0x4e };
> +	struct resource wdt_res = {};
>  	int err = -ENODEV;
>  	int i;
>  
> @@ -573,12 +593,26 @@ static int __init fintek_wdt_init(void)
>  	if (i == ARRAY_SIZE(addrs))
>  		return err;
>  
> -	return watchdog_init(addrs[i]);
> +	platform_driver_register(&fintek_wdt_driver);
> +
> +	wdt_res.name = "superio port";
> +	wdt_res.flags = IORESOURCE_IO;
> +	wdt_res.start = addrs[i];
> +	wdt_res.end   = addrs[i] + 1;
> +
> +	fintek_wdt_pdev = platform_device_register_simple(DRVNAME, -1, &wdt_res, 1);
> +	if (IS_ERR(fintek_wdt_pdev)) {
> +		platform_driver_unregister(&fintek_wdt_driver);
> +		return PTR_ERR(fintek_wdt_pdev);
> +	}
> +
> +	return 0;
>  }
>  
>  static void __exit fintek_wdt_exit(void)
>  {
> -	watchdog_unregister_device(&watchdog.wdd);
> +	platform_device_unregister(fintek_wdt_pdev);
> +	platform_driver_unregister(&fintek_wdt_driver);
>  }
>  
>  MODULE_DESCRIPTION("F71808E Watchdog Driver");
> -- 
> git-series 0.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ