Commit ff577fbc authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Khalid Elmously

media-devnode: fix namespace mess

BugLink: https://bugs.launchpad.net/bugs/1883916

commit 163f1e93 upstream.

Along all media controller code, "mdev" is used to represent
a pointer to struct media_device, and "devnode" for a pointer
to struct media_devnode.

However, inside media-devnode.[ch], "mdev" is used to represent
a pointer to struct media_devnode.

This is very confusing and may lead to development errors.

So, let's change all occurrences at media-devnode.[ch] to
also use "devnode" for such pointers.

This patch doesn't make any functional changes.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
[bwh: Backported to 4.4: adjust filename, context]
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 0696384a
...@@ -59,21 +59,21 @@ static DECLARE_BITMAP(media_devnode_nums, MEDIA_NUM_DEVICES); ...@@ -59,21 +59,21 @@ static DECLARE_BITMAP(media_devnode_nums, MEDIA_NUM_DEVICES);
/* Called when the last user of the media device exits. */ /* Called when the last user of the media device exits. */
static void media_devnode_release(struct device *cd) static void media_devnode_release(struct device *cd)
{ {
struct media_devnode *mdev = to_media_devnode(cd); struct media_devnode *devnode = to_media_devnode(cd);
mutex_lock(&media_devnode_lock); mutex_lock(&media_devnode_lock);
/* Delete the cdev on this minor as well */ /* Delete the cdev on this minor as well */
cdev_del(&mdev->cdev); cdev_del(&devnode->cdev);
/* Mark device node number as free */ /* Mark device node number as free */
clear_bit(mdev->minor, media_devnode_nums); clear_bit(devnode->minor, media_devnode_nums);
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
/* Release media_devnode and perform other cleanups as needed. */ /* Release media_devnode and perform other cleanups as needed. */
if (mdev->release) if (devnode->release)
mdev->release(mdev); devnode->release(devnode);
} }
static struct bus_type media_bus_type = { static struct bus_type media_bus_type = {
...@@ -83,37 +83,37 @@ static struct bus_type media_bus_type = { ...@@ -83,37 +83,37 @@ static struct bus_type media_bus_type = {
static ssize_t media_read(struct file *filp, char __user *buf, static ssize_t media_read(struct file *filp, char __user *buf,
size_t sz, loff_t *off) size_t sz, loff_t *off)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
if (!mdev->fops->read) if (!devnode->fops->read)
return -EINVAL; return -EINVAL;
if (!media_devnode_is_registered(mdev)) if (!media_devnode_is_registered(devnode))
return -EIO; return -EIO;
return mdev->fops->read(filp, buf, sz, off); return devnode->fops->read(filp, buf, sz, off);
} }
static ssize_t media_write(struct file *filp, const char __user *buf, static ssize_t media_write(struct file *filp, const char __user *buf,
size_t sz, loff_t *off) size_t sz, loff_t *off)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
if (!mdev->fops->write) if (!devnode->fops->write)
return -EINVAL; return -EINVAL;
if (!media_devnode_is_registered(mdev)) if (!media_devnode_is_registered(devnode))
return -EIO; return -EIO;
return mdev->fops->write(filp, buf, sz, off); return devnode->fops->write(filp, buf, sz, off);
} }
static unsigned int media_poll(struct file *filp, static unsigned int media_poll(struct file *filp,
struct poll_table_struct *poll) struct poll_table_struct *poll)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
if (!media_devnode_is_registered(mdev)) if (!media_devnode_is_registered(devnode))
return POLLERR | POLLHUP; return POLLERR | POLLHUP;
if (!mdev->fops->poll) if (!devnode->fops->poll)
return DEFAULT_POLLMASK; return DEFAULT_POLLMASK;
return mdev->fops->poll(filp, poll); return devnode->fops->poll(filp, poll);
} }
static long static long
...@@ -121,12 +121,12 @@ __media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg, ...@@ -121,12 +121,12 @@ __media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg,
long (*ioctl_func)(struct file *filp, unsigned int cmd, long (*ioctl_func)(struct file *filp, unsigned int cmd,
unsigned long arg)) unsigned long arg))
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
if (!ioctl_func) if (!ioctl_func)
return -ENOTTY; return -ENOTTY;
if (!media_devnode_is_registered(mdev)) if (!media_devnode_is_registered(devnode))
return -EIO; return -EIO;
return ioctl_func(filp, cmd, arg); return ioctl_func(filp, cmd, arg);
...@@ -134,9 +134,9 @@ __media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg, ...@@ -134,9 +134,9 @@ __media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg,
static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
return __media_ioctl(filp, cmd, arg, mdev->fops->ioctl); return __media_ioctl(filp, cmd, arg, devnode->fops->ioctl);
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -144,9 +144,9 @@ static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -144,9 +144,9 @@ static long media_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
static long media_compat_ioctl(struct file *filp, unsigned int cmd, static long media_compat_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
return __media_ioctl(filp, cmd, arg, mdev->fops->compat_ioctl); return __media_ioctl(filp, cmd, arg, devnode->fops->compat_ioctl);
} }
#endif /* CONFIG_COMPAT */ #endif /* CONFIG_COMPAT */
...@@ -154,7 +154,7 @@ static long media_compat_ioctl(struct file *filp, unsigned int cmd, ...@@ -154,7 +154,7 @@ static long media_compat_ioctl(struct file *filp, unsigned int cmd,
/* Override for the open function */ /* Override for the open function */
static int media_open(struct inode *inode, struct file *filp) static int media_open(struct inode *inode, struct file *filp)
{ {
struct media_devnode *mdev; struct media_devnode *devnode;
int ret; int ret;
/* Check if the media device is available. This needs to be done with /* Check if the media device is available. This needs to be done with
...@@ -164,23 +164,23 @@ static int media_open(struct inode *inode, struct file *filp) ...@@ -164,23 +164,23 @@ static int media_open(struct inode *inode, struct file *filp)
* a crash. * a crash.
*/ */
mutex_lock(&media_devnode_lock); mutex_lock(&media_devnode_lock);
mdev = container_of(inode->i_cdev, struct media_devnode, cdev); devnode = container_of(inode->i_cdev, struct media_devnode, cdev);
/* return ENXIO if the media device has been removed /* return ENXIO if the media device has been removed
already or if it is not registered anymore. */ already or if it is not registered anymore. */
if (!media_devnode_is_registered(mdev)) { if (!media_devnode_is_registered(devnode)) {
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
return -ENXIO; return -ENXIO;
} }
/* and increase the device refcount */ /* and increase the device refcount */
get_device(&mdev->dev); get_device(&devnode->dev);
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
filp->private_data = mdev; filp->private_data = devnode;
if (mdev->fops->open) { if (devnode->fops->open) {
ret = mdev->fops->open(filp); ret = devnode->fops->open(filp);
if (ret) { if (ret) {
put_device(&mdev->dev); put_device(&devnode->dev);
filp->private_data = NULL; filp->private_data = NULL;
return ret; return ret;
} }
...@@ -192,16 +192,16 @@ static int media_open(struct inode *inode, struct file *filp) ...@@ -192,16 +192,16 @@ static int media_open(struct inode *inode, struct file *filp)
/* Override for the release function */ /* Override for the release function */
static int media_release(struct inode *inode, struct file *filp) static int media_release(struct inode *inode, struct file *filp)
{ {
struct media_devnode *mdev = media_devnode_data(filp); struct media_devnode *devnode = media_devnode_data(filp);
if (mdev->fops->release) if (devnode->fops->release)
mdev->fops->release(filp); devnode->fops->release(filp);
filp->private_data = NULL; filp->private_data = NULL;
/* decrease the refcount unconditionally since the release() /* decrease the refcount unconditionally since the release()
return value is ignored. */ return value is ignored. */
put_device(&mdev->dev); put_device(&devnode->dev);
return 0; return 0;
} }
...@@ -221,7 +221,7 @@ static const struct file_operations media_devnode_fops = { ...@@ -221,7 +221,7 @@ static const struct file_operations media_devnode_fops = {
/** /**
* media_devnode_register - register a media device node * media_devnode_register - register a media device node
* @mdev: media device node structure we want to register * @devnode: media device node structure we want to register
* *
* The registration code assigns minor numbers and registers the new device node * The registration code assigns minor numbers and registers the new device node
* with the kernel. An error is returned if no free minor number can be found, * with the kernel. An error is returned if no free minor number can be found,
...@@ -233,7 +233,7 @@ static const struct file_operations media_devnode_fops = { ...@@ -233,7 +233,7 @@ static const struct file_operations media_devnode_fops = {
* the media_devnode structure is *not* called, so the caller is responsible for * the media_devnode structure is *not* called, so the caller is responsible for
* freeing any data. * freeing any data.
*/ */
int __must_check media_devnode_register(struct media_devnode *mdev, int __must_check media_devnode_register(struct media_devnode *devnode,
struct module *owner) struct module *owner)
{ {
int minor; int minor;
...@@ -251,40 +251,40 @@ int __must_check media_devnode_register(struct media_devnode *mdev, ...@@ -251,40 +251,40 @@ int __must_check media_devnode_register(struct media_devnode *mdev,
set_bit(minor, media_devnode_nums); set_bit(minor, media_devnode_nums);
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
mdev->minor = minor; devnode->minor = minor;
/* Part 2: Initialize and register the character device */ /* Part 2: Initialize and register the character device */
cdev_init(&mdev->cdev, &media_devnode_fops); cdev_init(&devnode->cdev, &media_devnode_fops);
mdev->cdev.owner = owner; devnode->cdev.owner = owner;
ret = cdev_add(&mdev->cdev, MKDEV(MAJOR(media_dev_t), mdev->minor), 1); ret = cdev_add(&devnode->cdev, MKDEV(MAJOR(media_dev_t), devnode->minor), 1);
if (ret < 0) { if (ret < 0) {
pr_err("%s: cdev_add failed\n", __func__); pr_err("%s: cdev_add failed\n", __func__);
goto error; goto error;
} }
/* Part 3: Register the media device */ /* Part 3: Register the media device */
mdev->dev.bus = &media_bus_type; devnode->dev.bus = &media_bus_type;
mdev->dev.devt = MKDEV(MAJOR(media_dev_t), mdev->minor); devnode->dev.devt = MKDEV(MAJOR(media_dev_t), devnode->minor);
mdev->dev.release = media_devnode_release; devnode->dev.release = media_devnode_release;
if (mdev->parent) if (devnode->parent)
mdev->dev.parent = mdev->parent; devnode->dev.parent = devnode->parent;
dev_set_name(&mdev->dev, "media%d", mdev->minor); dev_set_name(&devnode->dev, "media%d", devnode->minor);
ret = device_register(&mdev->dev); ret = device_register(&devnode->dev);
if (ret < 0) { if (ret < 0) {
pr_err("%s: device_register failed\n", __func__); pr_err("%s: device_register failed\n", __func__);
goto error; goto error;
} }
/* Part 4: Activate this minor. The char device can now be used. */ /* Part 4: Activate this minor. The char device can now be used. */
set_bit(MEDIA_FLAG_REGISTERED, &mdev->flags); set_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
return 0; return 0;
error: error:
mutex_lock(&media_devnode_lock); mutex_lock(&media_devnode_lock);
cdev_del(&mdev->cdev); cdev_del(&devnode->cdev);
clear_bit(mdev->minor, media_devnode_nums); clear_bit(devnode->minor, media_devnode_nums);
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
return ret; return ret;
...@@ -292,7 +292,7 @@ int __must_check media_devnode_register(struct media_devnode *mdev, ...@@ -292,7 +292,7 @@ int __must_check media_devnode_register(struct media_devnode *mdev,
/** /**
* media_devnode_unregister - unregister a media device node * media_devnode_unregister - unregister a media device node
* @mdev: the device node to unregister * @devnode: the device node to unregister
* *
* This unregisters the passed device. Future open calls will be met with * This unregisters the passed device. Future open calls will be met with
* errors. * errors.
...@@ -300,16 +300,16 @@ int __must_check media_devnode_register(struct media_devnode *mdev, ...@@ -300,16 +300,16 @@ int __must_check media_devnode_register(struct media_devnode *mdev,
* This function can safely be called if the device node has never been * This function can safely be called if the device node has never been
* registered or has already been unregistered. * registered or has already been unregistered.
*/ */
void media_devnode_unregister(struct media_devnode *mdev) void media_devnode_unregister(struct media_devnode *devnode)
{ {
/* Check if mdev was ever registered at all */ /* Check if devnode was ever registered at all */
if (!media_devnode_is_registered(mdev)) if (!media_devnode_is_registered(devnode))
return; return;
mutex_lock(&media_devnode_lock); mutex_lock(&media_devnode_lock);
clear_bit(MEDIA_FLAG_REGISTERED, &mdev->flags); clear_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
mutex_unlock(&media_devnode_lock); mutex_unlock(&media_devnode_lock);
device_unregister(&mdev->dev); device_unregister(&devnode->dev);
} }
/* /*
......
...@@ -80,24 +80,24 @@ struct media_devnode { ...@@ -80,24 +80,24 @@ struct media_devnode {
unsigned long flags; /* Use bitops to access flags */ unsigned long flags; /* Use bitops to access flags */
/* callbacks */ /* callbacks */
void (*release)(struct media_devnode *mdev); void (*release)(struct media_devnode *devnode);
}; };
/* dev to media_devnode */ /* dev to media_devnode */
#define to_media_devnode(cd) container_of(cd, struct media_devnode, dev) #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
int __must_check media_devnode_register(struct media_devnode *mdev, int __must_check media_devnode_register(struct media_devnode *devnode,
struct module *owner); struct module *owner);
void media_devnode_unregister(struct media_devnode *mdev); void media_devnode_unregister(struct media_devnode *devnode);
static inline struct media_devnode *media_devnode_data(struct file *filp) static inline struct media_devnode *media_devnode_data(struct file *filp)
{ {
return filp->private_data; return filp->private_data;
} }
static inline int media_devnode_is_registered(struct media_devnode *mdev) static inline int media_devnode_is_registered(struct media_devnode *devnode)
{ {
return test_bit(MEDIA_FLAG_REGISTERED, &mdev->flags); return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
} }
#endif /* _MEDIA_DEVNODE_H */ #endif /* _MEDIA_DEVNODE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment