Skip to content

Commit

Permalink
Merge branch 'drm-minor' into drm-next
Browse files Browse the repository at this point in the history
Fix minor conflicts with drm-anon:
 - allocation/free order
 - drm_device header cleanups
  • Loading branch information
David Herrmann committed Mar 16, 2014
2 parents afab446 + 0d63988 commit 07b48c3
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 193 deletions.
4 changes: 2 additions & 2 deletions drivers/gpu/drm/drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ long drm_ioctl(struct file *filp,

DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n",
task_pid_nr(current),
(long)old_encode_dev(file_priv->minor->device),
(long)old_encode_dev(file_priv->minor->kdev->devt),
file_priv->authenticated, ioctl->name);

/* Do not trust userspace, use our own definition */
Expand Down Expand Up @@ -402,7 +402,7 @@ long drm_ioctl(struct file *filp,
if (!ioctl)
DRM_DEBUG("invalid ioctl: pid=%d, dev=0x%lx, auth=%d, cmd=0x%02x, nr=0x%02x\n",
task_pid_nr(current),
(long)old_encode_dev(file_priv->minor->device),
(long)old_encode_dev(file_priv->minor->kdev->devt),
file_priv->authenticated, cmd, nr);

if (kdata != stack_kdata)
Expand Down
70 changes: 30 additions & 40 deletions drivers/gpu/drm/drm_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
#include <linux/slab.h>
#include <linux/module.h>

/* from BKL pushdown: note that nothing else serializes idr_find() */
/* from BKL pushdown */
DEFINE_MUTEX(drm_global_mutex);
EXPORT_SYMBOL(drm_global_mutex);

static int drm_open_helper(struct inode *inode, struct file *filp,
struct drm_device * dev);
struct drm_minor *minor);

static int drm_setup(struct drm_device * dev)
{
Expand Down Expand Up @@ -79,29 +79,23 @@ static int drm_setup(struct drm_device * dev)
*/
int drm_open(struct inode *inode, struct file *filp)
{
struct drm_device *dev = NULL;
int minor_id = iminor(inode);
struct drm_device *dev;
struct drm_minor *minor;
int retcode = 0;
int retcode;
int need_setup = 0;

minor = idr_find(&drm_minors_idr, minor_id);
if (!minor)
return -ENODEV;

if (!(dev = minor->dev))
return -ENODEV;

if (drm_device_is_unplugged(dev))
return -ENODEV;
minor = drm_minor_acquire(iminor(inode));
if (IS_ERR(minor))
return PTR_ERR(minor);

dev = minor->dev;
if (!dev->open_count++)
need_setup = 1;

/* share address_space across all char-devs of a single device */
filp->f_mapping = dev->anon_inode->i_mapping;

retcode = drm_open_helper(inode, filp, dev);
retcode = drm_open_helper(inode, filp, minor);
if (retcode)
goto err_undo;
if (need_setup) {
Expand All @@ -113,6 +107,7 @@ int drm_open(struct inode *inode, struct file *filp)

err_undo:
dev->open_count--;
drm_minor_release(minor);
return retcode;
}
EXPORT_SYMBOL(drm_open);
Expand All @@ -128,33 +123,30 @@ EXPORT_SYMBOL(drm_open);
*/
int drm_stub_open(struct inode *inode, struct file *filp)
{
struct drm_device *dev = NULL;
struct drm_device *dev;
struct drm_minor *minor;
int minor_id = iminor(inode);
int err = -ENODEV;
const struct file_operations *new_fops;

DRM_DEBUG("\n");

mutex_lock(&drm_global_mutex);
minor = idr_find(&drm_minors_idr, minor_id);
if (!minor)
goto out;

if (!(dev = minor->dev))
goto out;

if (drm_device_is_unplugged(dev))
goto out;
minor = drm_minor_acquire(iminor(inode));
if (IS_ERR(minor))
goto out_unlock;

dev = minor->dev;
new_fops = fops_get(dev->driver->fops);
if (!new_fops)
goto out;
goto out_release;

replace_fops(filp, new_fops);
if (filp->f_op->open)
err = filp->f_op->open(inode, filp);
out:

out_release:
drm_minor_release(minor);
out_unlock:
mutex_unlock(&drm_global_mutex);
return err;
}
Expand All @@ -181,16 +173,16 @@ static int drm_cpu_valid(void)
*
* \param inode device inode.
* \param filp file pointer.
* \param dev device.
* \param minor acquired minor-object.
* \return zero on success or a negative number on failure.
*
* Creates and initializes a drm_file structure for the file private data in \p
* filp and add it into the double linked list in \p dev.
*/
static int drm_open_helper(struct inode *inode, struct file *filp,
struct drm_device * dev)
struct drm_minor *minor)
{
int minor_id = iminor(inode);
struct drm_device *dev = minor->dev;
struct drm_file *priv;
int ret;

Expand All @@ -201,7 +193,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
if (dev->switch_power_state != DRM_SWITCH_POWER_ON && dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF)
return -EINVAL;

DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor->index);

priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
Expand All @@ -211,11 +203,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
priv->filp = filp;
priv->uid = current_euid();
priv->pid = get_pid(task_pid(current));
priv->minor = idr_find(&drm_minors_idr, minor_id);
if (!priv->minor) {
ret = -ENODEV;
goto out_put_pid;
}
priv->minor = minor;

/* for compatibility root is always authenticated */
priv->always_authenticated = capable(CAP_SYS_ADMIN);
Expand Down Expand Up @@ -321,7 +309,6 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
drm_prime_destroy_file_private(&priv->prime);
if (dev->driver->driver_features & DRIVER_GEM)
drm_gem_release(dev, priv);
out_put_pid:
put_pid(priv->pid);
kfree(priv);
filp->private_data = NULL;
Expand Down Expand Up @@ -442,7 +429,8 @@ int drm_lastclose(struct drm_device * dev)
int drm_release(struct inode *inode, struct file *filp)
{
struct drm_file *file_priv = filp->private_data;
struct drm_device *dev = file_priv->minor->dev;
struct drm_minor *minor = file_priv->minor;
struct drm_device *dev = minor->dev;
int retcode = 0;

mutex_lock(&drm_global_mutex);
Expand All @@ -458,7 +446,7 @@ int drm_release(struct inode *inode, struct file *filp)

DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
task_pid_nr(current),
(long)old_encode_dev(file_priv->minor->device),
(long)old_encode_dev(file_priv->minor->kdev->devt),
dev->open_count);

/* Release any auth tokens that might point to this file_priv,
Expand Down Expand Up @@ -561,6 +549,8 @@ int drm_release(struct inode *inode, struct file *filp)
}
mutex_unlock(&drm_global_mutex);

drm_minor_release(minor);

return retcode;
}
EXPORT_SYMBOL(drm_release);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/drm_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
drm_pci_agp_destroy(dev);
pci_disable_device(pdev);
err_free:
drm_dev_free(dev);
drm_dev_unref(dev);
return ret;
}
EXPORT_SYMBOL(drm_get_pci_dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/drm_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int drm_get_platform_dev(struct platform_device *platdev,
return 0;

err_free:
drm_dev_free(dev);
drm_dev_unref(dev);
return ret;
}

Expand Down
Loading

0 comments on commit 07b48c3

Please sign in to comment.