Commit b87c49b1 authored by Randy Dunlap's avatar Randy Dunlap Committed by Jeff Garzik

[PATCH] busmouse: fix memory leak and misc_register failure

From Flavio B. Leitner. <fbl@netbank.com.br>

Fix a memory leak and an unchecked return code in the busmouse driver.
parent 241d1557
...@@ -357,25 +357,23 @@ int register_busmouse(struct busmouse *ops) ...@@ -357,25 +357,23 @@ int register_busmouse(struct busmouse *ops)
{ {
unsigned int msedev = MINOR_TO_MOUSE(ops->minor); unsigned int msedev = MINOR_TO_MOUSE(ops->minor);
struct busmouse_data *mse; struct busmouse_data *mse;
int ret; int ret = -EINVAL;
if (msedev >= NR_MICE) { if (msedev >= NR_MICE) {
printk(KERN_ERR "busmouse: trying to allocate mouse on minor %d\n", printk(KERN_ERR "busmouse: trying to allocate mouse on minor %d\n",
ops->minor); ops->minor);
return -EINVAL; goto out;
} }
ret = -ENOMEM;
mse = kmalloc(sizeof(*mse), GFP_KERNEL); mse = kmalloc(sizeof(*mse), GFP_KERNEL);
if (!mse) if (!mse)
return -ENOMEM; goto out;
down(&mouse_sem); down(&mouse_sem);
ret = -EBUSY;
if (busmouse_data[msedev]) if (busmouse_data[msedev])
{ goto freemem;
up(&mouse_sem);
kfree(mse);
return -EBUSY;
}
memset(mse, 0, sizeof(*mse)); memset(mse, 0, sizeof(*mse));
...@@ -386,14 +384,22 @@ int register_busmouse(struct busmouse *ops) ...@@ -386,14 +384,22 @@ int register_busmouse(struct busmouse *ops)
mse->lock = (spinlock_t)SPIN_LOCK_UNLOCKED; mse->lock = (spinlock_t)SPIN_LOCK_UNLOCKED;
init_waitqueue_head(&mse->wait); init_waitqueue_head(&mse->wait);
busmouse_data[msedev] = mse;
ret = misc_register(&mse->miscdev); ret = misc_register(&mse->miscdev);
if (!ret)
if (ret < 0)
goto freemem;
busmouse_data[msedev] = mse;
ret = msedev; ret = msedev;
out:
up(&mouse_sem); up(&mouse_sem);
return ret; return ret;
freemem:
kfree(mse);
goto out;
} }
/** /**
......
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