[PATCH v5 01/16] chardev: add helper function to register char devs with a struct device

2017-03-17 Thread Logan Gunthorpe
Credit for this patch goes is shared with Dan Williams [1]. I've taken things one step further to make the helper function more useful and clean up calling code. There's a common pattern in the kernel whereby a struct cdev is placed in a structure along side a struct device which manages the life-

[PATCH v5 12/16] mtd: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
This is not as straightforward a conversion as the others in this series. These drivers did not originally make use of kobj.parent so they likely suffered from a use after free bug if someone unregistered the devices while they are being used. In order to make the conversions, switch from device_r

[PATCH v5 07/16] platform/chrome: cros_ec_dev - utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. At the same time we cleanup the error path through device_probe func

[PATCH v5 04/16] input: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper in evdev, joydev and mousedev. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Acked-

[PATCH v5 08/16] IB/ucm: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
From: Jason Gunthorpe The use after free is not triggerable here because the cdev holds the module lock and the only device_unregister is only triggered by module unload, however make the change for consistency. To make this work the cdev_del needs to move out of the struct device release functi

[PATCH v5 11/16] media: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Acked-by: Hans Verkuil --- drivers

[PATCH v5 09/16] infiniband: utilize the new cdev_set_parent function

2017-03-17 Thread Logan Gunthorpe
This replaces the suspect looking cdev.kobj.parent lines with the equivalent cdev_set_parent function. This is a straightforward change that's largely cosmetic but it does push the kobj.parent ownership into char_dev.c where it belongs. Signed-off-by: Logan Gunthorpe --- drivers/infiniband/core/

[PATCH v5 10/16] iio:core: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. In doing so we have to remove a guard statement from cdev_del, but t

[PATCH v5 00/16] Cleanup chardev instances with helper function

2017-03-17 Thread Logan Gunthorpe
Hey, This version of the series fixes the issue found by the kbuild test robot with the rtc driver. I managed to reproduce the issue and this series fixes the problem. Logan Changes since v4: * Fix a kbuild robot issue with the rtc driver: the rtc driver sometimes does not want to add the cd

[PATCH v5 06/16] tpm-chip: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Reviewed-by: Jason Gunthorpe Review

[PATCH v5 03/16] device-dax: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Reviewed-by: Dan Williams Reviewed-

[PATCH v5 16/16] switchtec: utilize new device_add_cdev helper function

2017-03-17 Thread Logan Gunthorpe
Very straightforward conversion to device_add_cdev. Drop cdev_add and device_add and use cdev_device_add. Signed-off-by: Logan Gunthorpe --- drivers/pci/switch/switchtec.c | 11 ++- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci

[PATCH v5 14/16] rtc: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Mostly straightforward, but we had to remove the rtc_dev_add/del_device functions as they split up the cdev_add and the device_add. Doing this also revealed that there was likely another subtle bug: seeing cdev_add was done after device_register, the cdev probably was not ready before device_add w

[PATCH v5 13/16] rapidio: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
This driver did not originally set kobj.parent so it likely had potential a use after free bug which this patch fixes. We convert from device_register to device_initialize/cdev_device_add. While we are at it we use put_device instead of kfree (as recommended by the device_initialize documentation)

[PATCH v5 15/16] scsi: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
This driver did not set kobj.parent so it likely suffered from a potential use after free race if the user unregistered the device while it was in use. This was not so straightforward a conversion but I think this patch cleans up its probe's error path significantly. This patch adds device_initia

[PATCH v5 02/16] device-dax: fix cdev leak

2017-03-17 Thread Logan Gunthorpe
From: Dan Williams If device_add() fails, cleanup the cdev. Otherwise, we leak a kobj_map() with a stale device number. As Jason points out, there is a small possibility that userspace has opened and mapped the device in the time between cdev_add() and the device_add() failure. We need a new kil

[PATCH v5 05/16] gpiolib: utilize new cdev_device_add helper function

2017-03-17 Thread Logan Gunthorpe
Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Reviewed-by: Linus Walleij --- dri