[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vfj1k8CZN4mZPibAq9CUrUSaKhEwY_X98Yk6NfeRweARQ@mail.gmail.com>
Date: Sat, 16 Feb 2019 14:11:34 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Peng Hao <peng.hao2@....com.cn>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Arnd Bergmann <arnd@...db.de>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH V5 3/4] misc/pvpanic: Avoid initializing multiple pvpanic devices
On Sat, Feb 16, 2019 at 10:29 AM Peng Hao <peng.hao2@....com.cn> wrote:
>
> Avoid initializing multiple pvpanic devices when configure multiple
> pvpanic device driver type. Make sure that only one pvpanic device
> is working.
>
> Signed-off-by: Peng Hao <peng.hao2@....com.cn>
> ---
> drivers/misc/pvpanic/pvpanic.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
> index ccadec0..fbb5038 100644
> --- a/drivers/misc/pvpanic/pvpanic.c
> +++ b/drivers/misc/pvpanic/pvpanic.c
> @@ -15,10 +15,13 @@
> #include <linux/types.h>
>
> static struct {
> + struct mutex lock;
> struct platform_device *pdev;
> void __iomem *base;
> bool is_ioport;
> -} pvpanic_data;
> +} pvpanic_data = {
> + .lock = __MUTEX_INITIALIZER(pvpanic_data.lock),
> +};
>
> #define PVPANIC_PANICKED (1 << 0)
>
> @@ -50,6 +53,12 @@ int pvpanic_add_device(struct device *dev, struct resource *res)
> struct platform_device *pdev;
> int ret;
>
> + mutex_lock(&pvpanic_data.lock);
> + if (pvpanic_data.pdev) {
> + mutex_unlock(&pvpanic_data.lock);
> + return -EEXIST;
> + }
> +
> pdev = platform_device_alloc("pvpanic", -1);
> if (!pdev)
> return -ENOMEM;
> @@ -64,9 +73,11 @@ int pvpanic_add_device(struct device *dev, struct resource *res)
> if (ret)
> goto err;
> pvpanic_data.pdev = pdev;
OK, mutex basically protects pdev member in pvpanic_data. What about
->remove() stage?
> + mutex_unlock(&pvpanic_data.lock);
>
> return 0;
> err:
> + mutex_unlock(&pvpanic_data.lock);
> platform_device_put(pdev);
> return ret;
> }
> --
> 1.8.3.1
>
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists