On Sat, Feb 25, 2017 at 11:38:07PM -0700, Logan Gunthorpe wrote:
> 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 <log...@deltatee.com>
>  drivers/char/tpm/tpm-chip.c | 19 +++----------------
>  1 file changed, 3 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index a77262d..933f96e 100644
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -187,7 +187,6 @@ struct tpm_chip *tpm_chip_alloc(struct device *dev,
>  
>       cdev_init(&chip->cdev, &tpm_fops);
>       chip->cdev.owner = THIS_MODULE;
> -     chip->cdev.kobj.parent = &chip->dev.kobj;
>  
>       return chip;
>  
> @@ -230,27 +229,16 @@ static int tpm_add_char_device(struct tpm_chip *chip)
>  {
>       int rc;
>  
> -     rc = cdev_add(&chip->cdev, chip->dev.devt, 1);
> +     rc = cdev_device_add(&chip->cdev, &chip->dev);
>       if (rc) {
>               dev_err(&chip->dev,
> -                     "unable to cdev_add() %s, major %d, minor %d, err=%d\n",
> +                     "unable to cdev_device_add() %s, major %d, minor %d, 
> err=%d\n",
>                       dev_name(&chip->dev), MAJOR(chip->dev.devt),
>                       MINOR(chip->dev.devt), rc);
>  
>               return rc;
>       }
>  
> -     rc = device_add(&chip->dev);
> -     if (rc) {
> -             dev_err(&chip->dev,
> -                     "unable to device_register() %s, major %d, minor %d, 
> err=%d\n",
> -                     dev_name(&chip->dev), MAJOR(chip->dev.devt),
> -                     MINOR(chip->dev.devt), rc);
> -
> -             cdev_del(&chip->cdev);
> -             return rc;
> -     }

This will collide with the patch I sent:

https://patchwork.kernel.org/patch/9589001/

Jarkko: The resolution will be to continue to call tpm_del_char_device
from the cdev_device_add error path and drop all calls to cdev_del

Reviewed-by: Jason Gunthorpe <jguntho...@obsidianresearch.com>

Jason
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to