[PATCH] spufs: Fix oops when spufs module is not loaded

try_module_get returns true when NULL arguments, so
we first need to check if there is a module loaded before
getting the reference count.

Signed-off-by: Arnd Bergmann <arndb@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
Arnd Bergmann 2005-12-05 22:52:23 -05:00 committed by Paul Mackerras
parent d88cfffac0
commit b41305a39a
1 changed files with 6 additions and 4 deletions

View File

@ -37,11 +37,12 @@ asmlinkage long sys_spu_create(const char __user *name,
unsigned int flags, mode_t mode)
{
long ret;
struct module *owner = spufs_calls.owner;
ret = -ENOSYS;
if (try_module_get(spufs_calls.owner)) {
if (owner && try_module_get(spufs_calls.owner)) {
ret = spufs_calls.create_thread(name, flags, mode);
module_put(spufs_calls.owner);
module_put(owner);
}
return ret;
}
@ -51,16 +52,17 @@ asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
long ret;
struct file *filp;
int fput_needed;
struct module *owner = spufs_calls.owner;
ret = -ENOSYS;
if (try_module_get(spufs_calls.owner)) {
if (owner && try_module_get(owner)) {
ret = -EBADF;
filp = fget_light(fd, &fput_needed);
if (filp) {
ret = spufs_calls.spu_run(filp, unpc, ustatus);
fput_light(filp, fput_needed);
}
module_put(spufs_calls.owner);
module_put(owner);
}
return ret;
}