public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Mandeep Sandhu <mandeep.sandhu@cyaninc.com>
Cc: hjk@hansjkoch.de, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/4] uio: Simplify the lifetime logic of struct uio_device.
Date: Sun, 25 Jan 2015 20:33:16 +0800	[thread overview]
Message-ID: <20150125123316.GA9141@kroah.com> (raw)
In-Reply-To: <1421434179-3650-2-git-send-email-mandeep.sandhu@cyaninc.com>

On Fri, Jan 16, 2015 at 10:49:36AM -0800, Mandeep Sandhu wrote:
> Embed struct device into struct uio_device, and use
> the refcounting and the release method of struct device
> to control struct uio_device.
> 
> This allows device_create and device_destroy to be replaced
> with the more standard device_register and device_unregister,
> and allows the struct device reference count to act as a
> reference count on struct idev as well.
> 
> Tested-by: Mandeep Sandhu <mandeep.sandhu@cyaninc.com>
> Signed-off-by: Mandeep Sandhu <mandeep.sandhu@cyaninc.com>
> ---
>  drivers/uio/uio.c          | 41 ++++++++++++++++++++++++++---------------
>  include/linux/uio_driver.h |  3 ++-
>  2 files changed, 28 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> index 6276f13..350b81b 100644
> --- a/drivers/uio/uio.c
> +++ b/drivers/uio/uio.c
> @@ -16,7 +16,6 @@
>  #include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/poll.h>
> -#include <linux/device.h>
>  #include <linux/slab.h>
>  #include <linux/mm.h>
>  #include <linux/idr.h>
> @@ -270,7 +269,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
>  		if (!map_found) {
>  			map_found = 1;
>  			idev->map_dir = kobject_create_and_add("maps",
> -							&idev->dev->kobj);
> +							&idev->device.kobj);
>  			if (!idev->map_dir)
>  				goto err_map;
>  		}
> @@ -295,7 +294,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
>  		if (!portio_found) {
>  			portio_found = 1;
>  			idev->portio_dir = kobject_create_and_add("portio",
> -							&idev->dev->kobj);
> +							&idev->device.kobj);
>  			if (!idev->portio_dir)
>  				goto err_portio;
>  		}
> @@ -334,7 +333,7 @@ err_map_kobj:
>  		kobject_put(&map->kobj);
>  	}
>  	kobject_put(idev->map_dir);
> -	dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
> +	dev_err(&idev->device, "error creating sysfs files (%d)\n", ret);
>  	return ret;
>  }
>  
> @@ -371,7 +370,7 @@ static int uio_get_minor(struct uio_device *idev)
>  		idev->minor = retval;
>  		retval = 0;
>  	} else if (retval == -ENOSPC) {
> -		dev_err(idev->dev, "too many uio devices\n");
> +		dev_err(&idev->device, "too many uio devices\n");
>  		retval = -EINVAL;
>  	}
>  	mutex_unlock(&minor_lock);
> @@ -785,6 +784,13 @@ static void release_uio_class(void)
>  	uio_major_cleanup();
>  }
>  
> +static void uio_device_release(struct device *dev)
> +{
> +	struct uio_device *idev = dev_get_drvdata(dev);


No, calculate the offset of, then you don't need to mess with drvdata,
as that shouldn't be used by the "core" of a subsystem.

> +
> +	devm_kfree(dev->parent, idev);
> +}
> +
>  /**
>   * uio_register_device - register a new userspace IO device
>   * @owner:	module that creates the new device
> @@ -819,14 +825,19 @@ int __uio_register_device(struct module *owner,
>  	if (ret)
>  		return ret;
>  
> -	idev->dev = device_create(&uio_class, parent,
> -				  MKDEV(uio_major, idev->minor), idev,
> -				  "uio%d", idev->minor);
> -	if (IS_ERR(idev->dev)) {
> -		printk(KERN_ERR "UIO: device register failed\n");
> -		ret = PTR_ERR(idev->dev);
> +	idev->device.devt = MKDEV(uio_major, idev->minor);
> +	idev->device.class = &uio_class;
> +	idev->device.parent = parent;
> +	idev->device.release = uio_device_release;
> +	dev_set_drvdata(&idev->device, idev);

This will not be needed if you fix up the release function.

> +
> +	ret = kobject_set_name(&idev->device.kobj, "uio%d", idev->minor);

dev_set_name()?




> +	if (ret)
> +		goto err_device_create;
> +
> +	ret = device_register(&idev->device);
> +	if (ret)
>  		goto err_device_create;
> -	}
>  
>  	ret = uio_dev_add_attributes(idev);
>  	if (ret)
> @@ -835,7 +846,7 @@ int __uio_register_device(struct module *owner,
>  	info->uio_dev = idev;
>  
>  	if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
> -		ret = devm_request_irq(idev->dev, info->irq, uio_interrupt,
> +		ret = devm_request_irq(&idev->device, info->irq, uio_interrupt,
>  				  info->irq_flags, info->name, idev);
>  		if (ret)
>  			goto err_request_irq;
> @@ -846,7 +857,7 @@ int __uio_register_device(struct module *owner,
>  err_request_irq:
>  	uio_dev_del_attributes(idev);
>  err_uio_dev_add_attributes:
> -	device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
> +	device_unregister(&idev->device);
>  err_device_create:
>  	uio_free_minor(idev);
>  	return ret;
> @@ -871,7 +882,7 @@ void uio_unregister_device(struct uio_info *info)
>  
>  	uio_dev_del_attributes(idev);
>  
> -	device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
> +	device_unregister(&idev->device);
>  
>  	return;
>  }
> diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
> index 32c0e83..e8f7f82 100644
> --- a/include/linux/uio_driver.h
> +++ b/include/linux/uio_driver.h
> @@ -14,6 +14,7 @@
>  #ifndef _UIO_DRIVER_H_
>  #define _UIO_DRIVER_H_
>  
> +#include <linux/device.h>
>  #include <linux/fs.h>
>  #include <linux/interrupt.h>
>  
> @@ -65,7 +66,7 @@ struct uio_port {
>  
>  struct uio_device {
>          struct module           *owner;
> -        struct device           *dev;
> +	struct device           device;

No need to rename the variable, just change it from being a pointer.

thanks,

greg k-h

  reply	other threads:[~2015-01-25 16:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-16 18:49 [PATCH 0/4] uio hotplug support Mandeep Sandhu
2015-01-16 18:49 ` [PATCH 1/4] uio: Simplify the lifetime logic of struct uio_device Mandeep Sandhu
2015-01-25 12:33   ` Greg KH [this message]
2015-01-26 19:57     ` Mandeep Sandhu
2015-01-26 20:04       ` Greg KH
2015-01-16 18:49 ` [PATCH 2/4] uio: Remove unused uio_info mmap method Mandeep Sandhu
2015-01-16 18:49 ` [PATCH 3/4] libunload: A library to help remove open files Mandeep Sandhu
2015-01-25 12:36   ` Greg KH
2015-01-16 18:49 ` [PATCH 4/4] uio: Implement hotunplug support, using libunload Mandeep Sandhu

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=20150125123316.GA9141@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=hjk@hansjkoch.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mandeep.sandhu@cyaninc.com \
    --cc=viro@zeniv.linux.org.uk \
    /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