From mboxrd@z Thu Jan 1 00:00:00 1970 From: Logan Gunthorpe Subject: [PATCH 00/14] Cleanup chardev instances with helper function Date: Mon, 20 Feb 2017 22:00:39 -0700 Message-ID: <1487653253-11497-1-git-send-email-logang@deltatee.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cc: linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, rtc-linux-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, osd-dev-yNzVSZO3znNg9hUCZPvPmw@public.gmane.org, linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-gpio@vger.kernel.org Hello, Our story for this patch-set begins with a new driver I wrote and am in the process of submitting upstream. That driver creates a fairly standard char device and the code for it was copied from a similar instance in device-dax. However, upon review, Greg Kroah-Hartman noticed [1] a suspicious line that assigned to the parent field of the underlying kobject for the char device. I removed that from my code and endeavoured to remove it from the code I copied as well. However, Dan Williams pointed out [2] that this code is necessary for correct reference counting of the underlying structures. This prompted me to do a fair bit more research and investigation into whats going on and I found it to be a common pattern. (Although misleading and though required to be correct, frequently forgotten.) This pattern is used in at least 15 places in the kernel and probably should have been used in at least 5 more. This patch-set aims to correct this and hopefully prevent future developers from wasting their time on it. The first patch introduces a new helper API as originally proposed by Dan Williams [3]. Please see the commit message for that patch for a longer description of the problem and history. The subsequent patches either update correct instances to use the new API or fix incorrect usages to ensure the cdev correctly takes a reference count using the new API (this is noted in those patches). This moves all except four of the cdev.kobj.parent usages into the one cdev function, the remaining four are in the infiniband subsystem and I've left alone because that subsystem seems to make use of kobjects directly (instead of struct devices). These are noted in patch 7 of this series. This series is based on v4.10 with the exception of the last patch which is for my new driver which, as yet, has not been accepted upstream. @Dan the first patch in this series will need your sign-off. Thanks, Logan [1] https://lkml.org/lkml/2017/2/10/370 [2] https://lkml.org/lkml/2017/2/10/607 [3] https://lkml.org/lkml/2017/2/13/700 Logan Gunthorpe (14): chardev: add helper function to register char devs with a struct device device-dax: utilize new device_add_cdev helper function input: utilize new device_add_cdev helper function gpiolib: utilize new device_add_cdev helper function tpm-chip: utilize new device_add_cdev helper function platform/chrome: utilize new device_add_cdev helper function infiniband: utilize new device_add_cdev helper function iio:core: utilize new device_add_cdev helper function media: utilize new device_add_cdev helper function mtd: utilize new device_add_cdev helper function rapidio: utilize new device_add_cdev helper function rtc: utilize new device_add_cdev helper function scsi: utilize new device_add_cdev helper function switchtec: utilize new device_add_cdev helper function drivers/char/tpm/tpm-chip.c | 3 +-- drivers/dax/dax.c | 5 ++--- drivers/gpio/gpiolib.c | 3 +-- drivers/iio/industrialio-core.c | 3 +-- drivers/infiniband/core/ucm.c | 8 +++++--- drivers/input/evdev.c | 3 +-- drivers/input/joydev.c | 3 +-- drivers/input/mousedev.c | 3 +-- drivers/media/cec/cec-core.c | 3 +-- drivers/media/media-devnode.c | 3 +-- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- drivers/pci/switch/switchtec.c | 3 +-- drivers/platform/chrome/cros_ec_dev.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 9 ++++++--- drivers/rtc/rtc-dev.c | 3 +-- drivers/scsi/osd/osd_uld.c | 9 +++++---- fs/char_dev.c | 24 ++++++++++++++++++++++++ include/linux/cdev.h | 1 + 19 files changed, 65 insertions(+), 45 deletions(-) -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ale.deltatee.com (ale.deltatee.com [207.54.116.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BDE5C82215 for ; Mon, 20 Feb 2017 21:03:07 -0800 (PST) From: Logan Gunthorpe Date: Mon, 20 Feb 2017 22:00:39 -0700 Message-Id: <1487653253-11497-1-git-send-email-logang@deltatee.com> Subject: [PATCH 00/14] Cleanup chardev instances with helper function List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Hans Verkuil , Mauro Carvalho Chehab , Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen , Matt Porter , Alexandre Bounine , Andrew Morton , Joe Perches , Lorenzo Stoakes , Vladimir Zapolskiy , Alessandro Zummo , Alexandre Belloni , Boaz Harrosh , Benny Halevy , "James E.J. Bottomley" , "Martin K. Petersen" , Stephen Bates , Bjorn Helgaas Cc: linux-scsi@vger.kernel.org, rtc-linux@googlegroups.com, linux-gpio@vger.kernel.org, linux-iio@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, osd-dev@open-osd.org, linux-input@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org List-ID: Hello, Our story for this patch-set begins with a new driver I wrote and am in the process of submitting upstream. That driver creates a fairly standard char device and the code for it was copied from a similar instance in device-dax. However, upon review, Greg Kroah-Hartman noticed [1] a suspicious line that assigned to the parent field of the underlying kobject for the char device. I removed that from my code and endeavoured to remove it from the code I copied as well. However, Dan Williams pointed out [2] that this code is necessary for correct reference counting of the underlying structures. This prompted me to do a fair bit more research and investigation into whats going on and I found it to be a common pattern. (Although misleading and though required to be correct, frequently forgotten.) This pattern is used in at least 15 places in the kernel and probably should have been used in at least 5 more. This patch-set aims to correct this and hopefully prevent future developers from wasting their time on it. The first patch introduces a new helper API as originally proposed by Dan Williams [3]. Please see the commit message for that patch for a longer description of the problem and history. The subsequent patches either update correct instances to use the new API or fix incorrect usages to ensure the cdev correctly takes a reference count using the new API (this is noted in those patches). This moves all except four of the cdev.kobj.parent usages into the one cdev function, the remaining four are in the infiniband subsystem and I've left alone because that subsystem seems to make use of kobjects directly (instead of struct devices). These are noted in patch 7 of this series. This series is based on v4.10 with the exception of the last patch which is for my new driver which, as yet, has not been accepted upstream. @Dan the first patch in this series will need your sign-off. Thanks, Logan [1] https://lkml.org/lkml/2017/2/10/370 [2] https://lkml.org/lkml/2017/2/10/607 [3] https://lkml.org/lkml/2017/2/13/700 Logan Gunthorpe (14): chardev: add helper function to register char devs with a struct device device-dax: utilize new device_add_cdev helper function input: utilize new device_add_cdev helper function gpiolib: utilize new device_add_cdev helper function tpm-chip: utilize new device_add_cdev helper function platform/chrome: utilize new device_add_cdev helper function infiniband: utilize new device_add_cdev helper function iio:core: utilize new device_add_cdev helper function media: utilize new device_add_cdev helper function mtd: utilize new device_add_cdev helper function rapidio: utilize new device_add_cdev helper function rtc: utilize new device_add_cdev helper function scsi: utilize new device_add_cdev helper function switchtec: utilize new device_add_cdev helper function drivers/char/tpm/tpm-chip.c | 3 +-- drivers/dax/dax.c | 5 ++--- drivers/gpio/gpiolib.c | 3 +-- drivers/iio/industrialio-core.c | 3 +-- drivers/infiniband/core/ucm.c | 8 +++++--- drivers/input/evdev.c | 3 +-- drivers/input/joydev.c | 3 +-- drivers/input/mousedev.c | 3 +-- drivers/media/cec/cec-core.c | 3 +-- drivers/media/media-devnode.c | 3 +-- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- drivers/pci/switch/switchtec.c | 3 +-- drivers/platform/chrome/cros_ec_dev.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 9 ++++++--- drivers/rtc/rtc-dev.c | 3 +-- drivers/scsi/osd/osd_uld.c | 9 +++++---- fs/char_dev.c | 24 ++++++++++++++++++++++++ include/linux/cdev.h | 1 + 19 files changed, 65 insertions(+), 45 deletions(-) -- 2.1.4 _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ale.deltatee.com ([207.54.116.67]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cg2bY-0002mC-MX for linux-mtd@lists.infradead.org; Tue, 21 Feb 2017 05:03:14 +0000 From: Logan Gunthorpe To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Hans Verkuil , Mauro Carvalho Chehab , Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen , Matt Porter , Alexandre Bounine , Andrew Morton , Joe Perches , Lorenzo Stoakes , Vladimir Zapolskiy , Alessandro Zummo , Alexandre Belloni , Boaz Harrosh , Benny Halevy , "James E.J. Bottomley" , "Martin K. Petersen" , Stephen Bates , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, osd-dev@open-osd.org, linux-scsi@vger.kernel.org, rtc-linux@googlegroups.com, linux-mtd@lists.infradead.org, linux-media@vger.kernel.org, linux-iio@vger.kernel.org, linux-rdma@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Logan Gunthorpe Date: Mon, 20 Feb 2017 22:00:39 -0700 Message-Id: <1487653253-11497-1-git-send-email-logang@deltatee.com> Subject: [PATCH 00/14] Cleanup chardev instances with helper function List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hello, Our story for this patch-set begins with a new driver I wrote and am in the process of submitting upstream. That driver creates a fairly standard char device and the code for it was copied from a similar instance in device-dax. However, upon review, Greg Kroah-Hartman noticed [1] a suspicious line that assigned to the parent field of the underlying kobject for the char device. I removed that from my code and endeavoured to remove it from the code I copied as well. However, Dan Williams pointed out [2] that this code is necessary for correct reference counting of the underlying structures. This prompted me to do a fair bit more research and investigation into whats going on and I found it to be a common pattern. (Although misleading and though required to be correct, frequently forgotten.) This pattern is used in at least 15 places in the kernel and probably should have been used in at least 5 more. This patch-set aims to correct this and hopefully prevent future developers from wasting their time on it. The first patch introduces a new helper API as originally proposed by Dan Williams [3]. Please see the commit message for that patch for a longer description of the problem and history. The subsequent patches either update correct instances to use the new API or fix incorrect usages to ensure the cdev correctly takes a reference count using the new API (this is noted in those patches). This moves all except four of the cdev.kobj.parent usages into the one cdev function, the remaining four are in the infiniband subsystem and I've left alone because that subsystem seems to make use of kobjects directly (instead of struct devices). These are noted in patch 7 of this series. This series is based on v4.10 with the exception of the last patch which is for my new driver which, as yet, has not been accepted upstream. @Dan the first patch in this series will need your sign-off. Thanks, Logan [1] https://lkml.org/lkml/2017/2/10/370 [2] https://lkml.org/lkml/2017/2/10/607 [3] https://lkml.org/lkml/2017/2/13/700 Logan Gunthorpe (14): chardev: add helper function to register char devs with a struct device device-dax: utilize new device_add_cdev helper function input: utilize new device_add_cdev helper function gpiolib: utilize new device_add_cdev helper function tpm-chip: utilize new device_add_cdev helper function platform/chrome: utilize new device_add_cdev helper function infiniband: utilize new device_add_cdev helper function iio:core: utilize new device_add_cdev helper function media: utilize new device_add_cdev helper function mtd: utilize new device_add_cdev helper function rapidio: utilize new device_add_cdev helper function rtc: utilize new device_add_cdev helper function scsi: utilize new device_add_cdev helper function switchtec: utilize new device_add_cdev helper function drivers/char/tpm/tpm-chip.c | 3 +-- drivers/dax/dax.c | 5 ++--- drivers/gpio/gpiolib.c | 3 +-- drivers/iio/industrialio-core.c | 3 +-- drivers/infiniband/core/ucm.c | 8 +++++--- drivers/input/evdev.c | 3 +-- drivers/input/joydev.c | 3 +-- drivers/input/mousedev.c | 3 +-- drivers/media/cec/cec-core.c | 3 +-- drivers/media/media-devnode.c | 3 +-- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- drivers/pci/switch/switchtec.c | 3 +-- drivers/platform/chrome/cros_ec_dev.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 9 ++++++--- drivers/rtc/rtc-dev.c | 3 +-- drivers/scsi/osd/osd_uld.c | 9 +++++---- fs/char_dev.c | 24 ++++++++++++++++++++++++ include/linux/cdev.h | 1 + 19 files changed, 65 insertions(+), 45 deletions(-) -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Sender: rtc-linux@googlegroups.com MIME-Version: 1.0 Received: from ale.deltatee.com (ale.deltatee.com. [207.54.116.67]) by gmr-mx.google.com with ESMTPS id s64si2090539pfk.0.2017.02.20.21.02.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Feb 2017 21:02:52 -0800 (PST) From: Logan Gunthorpe To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Hans Verkuil , Mauro Carvalho Chehab , Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen , Matt Porter , Alexandre Bounine , Andrew Morton , Joe Perches , Lorenzo Stoakes , Vladimir Zapolskiy , Alessandro Zummo , Alexandre Belloni , Boaz Harrosh , Benny Halevy , "James E.J. Bottomley" , "Martin K. Petersen" , Stephen Bates , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, osd-dev@open-osd.org, linux-scsi@vger.kernel.org, rtc-linux@googlegroups.com, linux-mtd@lists.infradead.org, linux-media@vger.kernel.org, linux-iio@vger.kernel.org, linux-rdma@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Logan Gunthorpe Date: Mon, 20 Feb 2017 22:00:39 -0700 Message-Id: <1487653253-11497-1-git-send-email-logang@deltatee.com> Subject: [rtc-linux] [PATCH 00/14] Cleanup chardev instances with helper function Reply-To: rtc-linux@googlegroups.com Content-Type: text/plain; charset=UTF-8 List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Hello, Our story for this patch-set begins with a new driver I wrote and am in the process of submitting upstream. That driver creates a fairly standard char device and the code for it was copied from a similar instance in device-dax. However, upon review, Greg Kroah-Hartman noticed [1] a suspicious line that assigned to the parent field of the underlying kobject for the char device. I removed that from my code and endeavoured to remove it from the code I copied as well. However, Dan Williams pointed out [2] that this code is necessary for correct reference counting of the underlying structures. This prompted me to do a fair bit more research and investigation into whats going on and I found it to be a common pattern. (Although misleading and though required to be correct, frequently forgotten.) This pattern is used in at least 15 places in the kernel and probably should have been used in at least 5 more. This patch-set aims to correct this and hopefully prevent future developers from wasting their time on it. The first patch introduces a new helper API as originally proposed by Dan Williams [3]. Please see the commit message for that patch for a longer description of the problem and history. The subsequent patches either update correct instances to use the new API or fix incorrect usages to ensure the cdev correctly takes a reference count using the new API (this is noted in those patches). This moves all except four of the cdev.kobj.parent usages into the one cdev function, the remaining four are in the infiniband subsystem and I've left alone because that subsystem seems to make use of kobjects directly (instead of struct devices). These are noted in patch 7 of this series. This series is based on v4.10 with the exception of the last patch which is for my new driver which, as yet, has not been accepted upstream. @Dan the first patch in this series will need your sign-off. Thanks, Logan [1] https://lkml.org/lkml/2017/2/10/370 [2] https://lkml.org/lkml/2017/2/10/607 [3] https://lkml.org/lkml/2017/2/13/700 Logan Gunthorpe (14): chardev: add helper function to register char devs with a struct device device-dax: utilize new device_add_cdev helper function input: utilize new device_add_cdev helper function gpiolib: utilize new device_add_cdev helper function tpm-chip: utilize new device_add_cdev helper function platform/chrome: utilize new device_add_cdev helper function infiniband: utilize new device_add_cdev helper function iio:core: utilize new device_add_cdev helper function media: utilize new device_add_cdev helper function mtd: utilize new device_add_cdev helper function rapidio: utilize new device_add_cdev helper function rtc: utilize new device_add_cdev helper function scsi: utilize new device_add_cdev helper function switchtec: utilize new device_add_cdev helper function drivers/char/tpm/tpm-chip.c | 3 +-- drivers/dax/dax.c | 5 ++--- drivers/gpio/gpiolib.c | 3 +-- drivers/iio/industrialio-core.c | 3 +-- drivers/infiniband/core/ucm.c | 8 +++++--- drivers/input/evdev.c | 3 +-- drivers/input/joydev.c | 3 +-- drivers/input/mousedev.c | 3 +-- drivers/media/cec/cec-core.c | 3 +-- drivers/media/media-devnode.c | 3 +-- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- drivers/pci/switch/switchtec.c | 3 +-- drivers/platform/chrome/cros_ec_dev.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 9 ++++++--- drivers/rtc/rtc-dev.c | 3 +-- drivers/scsi/osd/osd_uld.c | 9 +++++---- fs/char_dev.c | 24 ++++++++++++++++++++++++ include/linux/cdev.h | 1 + 19 files changed, 65 insertions(+), 45 deletions(-) -- 2.1.4 -- You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. --- You received this message because you are subscribed to the Google Groups "rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Logan Gunthorpe Subject: [PATCH 00/14] Cleanup chardev instances with helper function Date: Mon, 20 Feb 2017 22:00:39 -0700 Message-ID: <1487653253-11497-1-git-send-email-logang@deltatee.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, rtc-linux-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, osd-dev-yNzVSZO3znNg9hUCZPvPmw@public.gmane.org, linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cameron Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" List-Id: linux-fsdevel.vger.kernel.org Hello, Our story for this patch-set begins with a new driver I wrote and am in the process of submitting upstream. That driver creates a fairly standard char device and the code for it was copied from a similar instance in device-dax. However, upon review, Greg Kroah-Hartman noticed [1] a suspicious line that assigned to the parent field of the underlying kobject for the char device. I removed that from my code and endeavoured to remove it from the code I copied as well. However, Dan Williams pointed out [2] that this code is necessary for correct reference counting of the underlying structures. This prompted me to do a fair bit more research and investigation into whats going on and I found it to be a common pattern. (Although misleading and though required to be correct, frequently forgotten.) This pattern is used in at least 15 places in the kernel and probably should have been used in at least 5 more. This patch-set aims to correct this and hopefully prevent future developers from wasting their time on it. The first patch introduces a new helper API as originally proposed by Dan Williams [3]. Please see the commit message for that patch for a longer description of the problem and history. The subsequent patches either update correct instances to use the new API or fix incorrect usages to ensure the cdev correctly takes a reference count using the new API (this is noted in those patches). This moves all except four of the cdev.kobj.parent usages into the one cdev function, the remaining four are in the infiniband subsystem and I've left alone because that subsystem seems to make use of kobjects directly (instead of struct devices). These are noted in patch 7 of this series. This series is based on v4.10 with the exception of the last patch which is for my new driver which, as yet, has not been accepted upstream. @Dan the first patch in this series will need your sign-off. Thanks, Logan [1] https://lkml.org/lkml/2017/2/10/370 [2] https://lkml.org/lkml/2017/2/10/607 [3] https://lkml.org/lkml/2017/2/13/700 Logan Gunthorpe (14): chardev: add helper function to register char devs with a struct device device-dax: utilize new device_add_cdev helper function input: utilize new device_add_cdev helper function gpiolib: utilize new device_add_cdev helper function tpm-chip: utilize new device_add_cdev helper function platform/chrome: utilize new device_add_cdev helper function infiniband: utilize new device_add_cdev helper function iio:core: utilize new device_add_cdev helper function media: utilize new device_add_cdev helper function mtd: utilize new device_add_cdev helper function rapidio: utilize new device_add_cdev helper function rtc: utilize new device_add_cdev helper function scsi: utilize new device_add_cdev helper function switchtec: utilize new device_add_cdev helper function drivers/char/tpm/tpm-chip.c | 3 +-- drivers/dax/dax.c | 5 ++--- drivers/gpio/gpiolib.c | 3 +-- drivers/iio/industrialio-core.c | 3 +-- drivers/infiniband/core/ucm.c | 8 +++++--- drivers/input/evdev.c | 3 +-- drivers/input/joydev.c | 3 +-- drivers/input/mousedev.c | 3 +-- drivers/media/cec/cec-core.c | 3 +-- drivers/media/media-devnode.c | 3 +-- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- drivers/pci/switch/switchtec.c | 3 +-- drivers/platform/chrome/cros_ec_dev.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 9 ++++++--- drivers/rtc/rtc-dev.c | 3 +-- drivers/scsi/osd/osd_uld.c | 9 +++++---- fs/char_dev.c | 24 ++++++++++++++++++++++++ include/linux/cdev.h | 1 + 19 files changed, 65 insertions(+), 45 deletions(-) -- 2.1.4