From: Logan Gunthorpe <logang@deltatee.com>
To: Keith Busch <keith.busch@intel.com>,
Myron Stowe <myron.stowe@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Jonathan Corbet <corbet@lwn.net>,
"David S. Miller" <davem@davemloft.net>,
Andrew Morton <akpm@linux-foundation.org>,
Emil Velikov <emil.l.velikov@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Linus Walleij <linus.walleij@linaro.org>,
Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
Wei Zhang <wzhang@fb.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: Kurt Schwemmer <kurt.schwemmer@microsemi.com>,
Stephen Bates <stephen.bates@microsemi.com>,
linux-pci@vger.kernel.org, linux-doc@vger.kernel.org,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] switchtec: cleanup cdev init
Date: Sat, 18 Feb 2017 13:22:20 -0700 [thread overview]
Message-ID: <20e55da4-b3c1-7c57-15cf-b0aa52442e18@deltatee.com> (raw)
In-Reply-To: <1486749440-24309-1-git-send-email-logang@deltatee.com>
Hi,
Please don't apply this patch and instead apply the switchtec driver as
we submitted in v2. As per the discussion in [1], not using the cdev's
kobj parent results in incorrect reference counting and a possible use
of the cdev after its containing structure is freed.
I've also done a quick review around the kernel and found the pattern in
question to be quite prevalent. It's used in, at least, these drivers:
drivers/dax/dax.c:708
drivers/input/evdev.c:1419
drivers/input/joydev.c:908
drivers/input/mousedev.c:904
drivers/gpio/gpiolib.c:1039
drivers/char/tpm/tpm-chip.c:190
drivers/platform/chrome/cros_ec_dev.c:411
drivers/infiniband/hw/hfi1/device.c:72
drivers/infiniband/core/uverbs_main.c:1168
drivers/infiniband/core/user_mad.c:1186
drivers/infiniband/core/user_mad.c:1205
drivers/iio/industrialio-core.c:1721
drivers/media/cec/cec-core.c:140
drivers/media/media-devnode.c:258
Dan Williams has proposed a helper API in [2] that could make this code
appear significantly less suspect which I think would be a good idea.
However, for now, I feel the switchtec code should also follow this
pattern (ie. the way it was submitted in v2) and can be changed or
cleaned up when/if the above numerous examples are fixed up.
Thanks,
Logan
[1] https://lkml.org/lkml/2017/2/10/589
[2] https://lkml.org/lkml/2017/2/13/700
On 10/02/17 10:57 AM, Logan Gunthorpe wrote:
> Per a suggestion from Greg Kroah-Hartman [1], don't set the cdev's
> kobject parent. This allows us to use device_register instead of init
> and add.
>
> [1] https://lkml.org/lkml/2017/2/10/370
> ---
> drivers/pci/switch/switchtec.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
> index 82bfd18..014eaec 100644
> --- a/drivers/pci/switch/switchtec.c
> +++ b/drivers/pci/switch/switchtec.c
> @@ -1222,24 +1222,23 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)
> return ERR_PTR(minor);
>
> dev = &stdev->dev;
> - device_initialize(dev);
> dev->devt = MKDEV(MAJOR(switchtec_devt), minor);
> - dev->class = switchtec_class;
> - dev->parent = &pdev->dev;
> - dev->groups = switchtec_device_groups;
> - dev->release = stdev_release;
> - dev_set_name(dev, "switchtec%d", minor);
>
> cdev = &stdev->cdev;
> cdev_init(cdev, &switchtec_fops);
> cdev->owner = THIS_MODULE;
> - cdev->kobj.parent = &dev->kobj;
>
> rc = cdev_add(&stdev->cdev, dev->devt, 1);
> if (rc)
> goto err_cdev;
>
> - rc = device_add(dev);
> + dev->class = switchtec_class;
> + dev->parent = &pdev->dev;
> + dev->groups = switchtec_device_groups;
> + dev->release = stdev_release;
> + dev_set_name(dev, "switchtec%d", minor);
> +
> + rc = device_register(dev);
> if (rc) {
> cdev_del(&stdev->cdev);
> put_device(dev);
>
next prev parent reply other threads:[~2017-02-18 20:41 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-02 18:05 [PATCH v2 0/4] New Microsemi PCI Switch Management Driver Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 1/4] MicroSemi Switchtec management interface driver Logan Gunthorpe
2017-02-10 14:51 ` Greg Kroah-Hartman
2017-02-10 16:48 ` Logan Gunthorpe
2017-02-10 16:55 ` Greg Kroah-Hartman
2017-02-10 17:03 ` Logan Gunthorpe
2017-02-10 17:09 ` Greg Kroah-Hartman
2017-02-10 18:00 ` Logan Gunthorpe
2017-02-10 17:57 ` [PATCH] switchtec: cleanup cdev init Logan Gunthorpe
2017-02-18 20:22 ` Logan Gunthorpe [this message]
2017-02-19 21:43 ` Dan Williams
2017-02-20 4:22 ` Logan Gunthorpe
2017-02-21 18:37 ` Jason Gunthorpe
2017-02-10 14:54 ` [PATCH v2 1/4] MicroSemi Switchtec management interface driver Greg Kroah-Hartman
2017-02-24 0:35 ` Bjorn Helgaas
2017-02-24 18:32 ` Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 2/4] switchtec: Add user interface documentation Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 3/4] switchtec: Add sysfs attributes to the Switchtec driver Logan Gunthorpe
2017-02-10 14:54 ` Greg Kroah-Hartman
2017-02-23 22:43 ` Bjorn Helgaas
2017-02-23 22:56 ` Logan Gunthorpe
2017-02-24 22:45 ` Bjorn Helgaas
2017-02-02 18:06 ` [PATCH v2 4/4] switchtec: Add IOCTLs " Logan Gunthorpe
2017-02-09 23:16 ` [PATCH v2 0/4] New Microsemi PCI Switch Management Driver Wei Zhang
2017-02-09 23:46 ` Wei Zhang
2017-02-10 14:54 ` Greg Kroah-Hartman
2017-02-10 16:14 ` Jens Axboe
2017-02-17 20:36 ` Logan Gunthorpe
2017-02-23 20:36 ` Logan Gunthorpe
2017-02-23 20:51 ` Sinan Kaya
2017-02-23 20:54 ` Jens Axboe
2017-02-23 20:56 ` Logan Gunthorpe
2017-02-23 20:52 ` Jens Axboe
2017-02-23 20:55 ` Greg Kroah-Hartman
2017-02-23 22:14 ` Bjorn Helgaas
2017-02-23 22:19 ` Logan Gunthorpe
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=20e55da4-b3c1-7c57-15cf-b0aa52442e18@deltatee.com \
--to=logang@deltatee.com \
--cc=akpm@linux-foundation.org \
--cc=bhelgaas@google.com \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=emil.l.velikov@gmail.com \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=keith.busch@intel.com \
--cc=konishi.ryusuke@lab.ntt.co.jp \
--cc=kurt.schwemmer@microsemi.com \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mchehab@kernel.org \
--cc=myron.stowe@gmail.com \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stephen.bates@microsemi.com \
--cc=wzhang@fb.com \
/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).