提交 60aa4924 编写于 作者: J Jonathan Corbet

Rationalize fasync return values

Most fasync implementations do something like:

     return fasync_helper(...);

But fasync_helper() will return a positive value at times - a feature used
in at least one place.  Thus, a number of other drivers do:

     err = fasync_helper(...);
     if (err < 0)
             return err;
     return 0;

In the interests of consistency and more concise code, it makes sense to
map positive return values onto zero where ->fasync() is called.

Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: NJonathan Corbet <corbet@lwn.net>
上级 76398425
...@@ -888,12 +888,7 @@ static irqreturn_t sonypi_irq(int irq, void *dev_id) ...@@ -888,12 +888,7 @@ static irqreturn_t sonypi_irq(int irq, void *dev_id)
static int sonypi_misc_fasync(int fd, struct file *filp, int on) static int sonypi_misc_fasync(int fd, struct file *filp, int on)
{ {
int retval; return fasync_helper(fd, filp, on, &sonypi_device.fifo_async);
retval = fasync_helper(fd, filp, on, &sonypi_device.fifo_async);
if (retval < 0)
return retval;
return 0;
} }
static int sonypi_misc_release(struct inode *inode, struct file *file) static int sonypi_misc_release(struct inode *inode, struct file *file)
......
...@@ -337,14 +337,10 @@ int drm_fasync(int fd, struct file *filp, int on) ...@@ -337,14 +337,10 @@ int drm_fasync(int fd, struct file *filp, int on)
{ {
struct drm_file *priv = filp->private_data; struct drm_file *priv = filp->private_data;
struct drm_device *dev = priv->minor->dev; struct drm_device *dev = priv->minor->dev;
int retcode;
DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
(long)old_encode_dev(priv->minor->device)); (long)old_encode_dev(priv->minor->device));
retcode = fasync_helper(fd, filp, on, &dev->buf_async); return fasync_helper(fd, filp, on, &dev->buf_async);
if (retcode < 0)
return retcode;
return 0;
} }
EXPORT_SYMBOL(drm_fasync); EXPORT_SYMBOL(drm_fasync);
......
...@@ -227,12 +227,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report) ...@@ -227,12 +227,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
*/ */
static int hiddev_fasync(int fd, struct file *file, int on) static int hiddev_fasync(int fd, struct file *file, int on)
{ {
int retval;
struct hiddev_list *list = file->private_data; struct hiddev_list *list = file->private_data;
retval = fasync_helper(fd, file, on, &list->fasync); return fasync_helper(fd, file, on, &list->fasync);
return retval < 0 ? retval : 0;
} }
......
...@@ -1325,11 +1325,7 @@ static int dv1394_fasync(int fd, struct file *file, int on) ...@@ -1325,11 +1325,7 @@ static int dv1394_fasync(int fd, struct file *file, int on)
struct video_card *video = file_to_video_card(file); struct video_card *video = file_to_video_card(file);
int retval = fasync_helper(fd, file, on, &video->fasync); return fasync_helper(fd, file, on, &video->fasync);
if (retval < 0)
return retval;
return 0;
} }
static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
......
...@@ -94,11 +94,8 @@ static void evdev_event(struct input_handle *handle, ...@@ -94,11 +94,8 @@ static void evdev_event(struct input_handle *handle,
static int evdev_fasync(int fd, struct file *file, int on) static int evdev_fasync(int fd, struct file *file, int on)
{ {
struct evdev_client *client = file->private_data; struct evdev_client *client = file->private_data;
int retval;
retval = fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0; return fasync_helper(fd, file, on, &client->fasync);
} }
static int evdev_flush(struct file *file, fl_owner_t id) static int evdev_flush(struct file *file, fl_owner_t id)
......
...@@ -159,12 +159,9 @@ static void joydev_event(struct input_handle *handle, ...@@ -159,12 +159,9 @@ static void joydev_event(struct input_handle *handle,
static int joydev_fasync(int fd, struct file *file, int on) static int joydev_fasync(int fd, struct file *file, int on)
{ {
int retval;
struct joydev_client *client = file->private_data; struct joydev_client *client = file->private_data;
retval = fasync_helper(fd, file, on, &client->fasync); return fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0;
} }
static void joydev_free(struct device *dev) static void joydev_free(struct device *dev)
......
...@@ -403,12 +403,9 @@ static void mousedev_event(struct input_handle *handle, ...@@ -403,12 +403,9 @@ static void mousedev_event(struct input_handle *handle,
static int mousedev_fasync(int fd, struct file *file, int on) static int mousedev_fasync(int fd, struct file *file, int on)
{ {
int retval;
struct mousedev_client *client = file->private_data; struct mousedev_client *client = file->private_data;
retval = fasync_helper(fd, file, on, &client->fasync); return fasync_helper(fd, file, on, &client->fasync);
return retval < 0 ? retval : 0;
} }
static void mousedev_free(struct device *dev) static void mousedev_free(struct device *dev)
......
...@@ -58,10 +58,8 @@ static unsigned int serio_raw_no; ...@@ -58,10 +58,8 @@ static unsigned int serio_raw_no;
static int serio_raw_fasync(int fd, struct file *file, int on) static int serio_raw_fasync(int fd, struct file *file, int on)
{ {
struct serio_raw_list *list = file->private_data; struct serio_raw_list *list = file->private_data;
int retval;
retval = fasync_helper(fd, file, on, &list->fasync); return fasync_helper(fd, file, on, &list->fasync);
return retval < 0 ? retval : 0;
} }
static struct serio_raw *serio_raw_locate(int minor) static struct serio_raw *serio_raw_locate(int minor)
......
...@@ -993,8 +993,8 @@ static struct fasync_struct *fasync[256] = { NULL, }; ...@@ -993,8 +993,8 @@ static struct fasync_struct *fasync[256] = { NULL, };
static int cosa_fasync(struct inode *inode, struct file *file, int on) static int cosa_fasync(struct inode *inode, struct file *file, int on)
{ {
int port = iminor(inode); int port = iminor(inode);
int rv = fasync_helper(inode, file, on, &fasync[port]);
return rv < 0 ? rv : 0; return fasync_helper(inode, file, on, &fasync[port]);
} }
#endif #endif
......
...@@ -1917,12 +1917,7 @@ static struct sonypi_compat_s sonypi_compat = { ...@@ -1917,12 +1917,7 @@ static struct sonypi_compat_s sonypi_compat = {
static int sonypi_misc_fasync(int fd, struct file *filp, int on) static int sonypi_misc_fasync(int fd, struct file *filp, int on)
{ {
int retval; return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
if (retval < 0)
return retval;
return 0;
} }
static int sonypi_misc_release(struct inode *inode, struct file *file) static int sonypi_misc_release(struct inode *inode, struct file *file)
......
...@@ -1154,7 +1154,6 @@ sg_poll(struct file *filp, poll_table * wait) ...@@ -1154,7 +1154,6 @@ sg_poll(struct file *filp, poll_table * wait)
static int static int
sg_fasync(int fd, struct file *filp, int mode) sg_fasync(int fd, struct file *filp, int mode)
{ {
int retval;
Sg_device *sdp; Sg_device *sdp;
Sg_fd *sfp; Sg_fd *sfp;
...@@ -1163,8 +1162,7 @@ sg_fasync(int fd, struct file *filp, int mode) ...@@ -1163,8 +1162,7 @@ sg_fasync(int fd, struct file *filp, int mode)
SCSI_LOG_TIMEOUT(3, printk("sg_fasync: %s, mode=%d\n", SCSI_LOG_TIMEOUT(3, printk("sg_fasync: %s, mode=%d\n",
sdp->disk->disk_name, mode)); sdp->disk->disk_name, mode));
retval = fasync_helper(fd, filp, mode, &sfp->async_qp); return fasync_helper(fd, filp, mode, &sfp->async_qp);
return (retval < 0) ? retval : 0;
} }
static int static int
......
...@@ -184,6 +184,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg) ...@@ -184,6 +184,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
if (error < 0) if (error < 0)
goto out; goto out;
if (error > 0)
error = 0;
} }
spin_lock(&filp->f_lock); spin_lock(&filp->f_lock);
filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK); filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
......
...@@ -432,7 +432,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp, ...@@ -432,7 +432,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
else else
error = -ENOTTY; error = -ENOTTY;
} }
return error; return error < 0 ? error : 0;
} }
static int ioctl_fsfreeze(struct file *filp) static int ioctl_fsfreeze(struct file *filp)
......
...@@ -667,10 +667,7 @@ pipe_read_fasync(int fd, struct file *filp, int on) ...@@ -667,10 +667,7 @@ pipe_read_fasync(int fd, struct file *filp, int on)
retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers); retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
if (retval < 0) return retval;
return retval;
return 0;
} }
...@@ -684,10 +681,7 @@ pipe_write_fasync(int fd, struct file *filp, int on) ...@@ -684,10 +681,7 @@ pipe_write_fasync(int fd, struct file *filp, int on)
retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers); retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
if (retval < 0) return retval;
return retval;
return 0;
} }
...@@ -706,11 +700,7 @@ pipe_rdwr_fasync(int fd, struct file *filp, int on) ...@@ -706,11 +700,7 @@ pipe_rdwr_fasync(int fd, struct file *filp, int on)
fasync_helper(-1, filp, 0, &pipe->fasync_readers); fasync_helper(-1, filp, 0, &pipe->fasync_readers);
} }
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return retval;
if (retval < 0)
return retval;
return 0;
} }
......
...@@ -1373,12 +1373,9 @@ EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat); ...@@ -1373,12 +1373,9 @@ EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat);
static int snd_ctl_fasync(int fd, struct file * file, int on) static int snd_ctl_fasync(int fd, struct file * file, int on)
{ {
struct snd_ctl_file *ctl; struct snd_ctl_file *ctl;
int err;
ctl = file->private_data; ctl = file->private_data;
err = fasync_helper(fd, file, on, &ctl->fasync); return fasync_helper(fd, file, on, &ctl->fasync);
if (err < 0)
return err;
return 0;
} }
/* /*
......
...@@ -3246,9 +3246,7 @@ static int snd_pcm_fasync(int fd, struct file * file, int on) ...@@ -3246,9 +3246,7 @@ static int snd_pcm_fasync(int fd, struct file * file, int on)
err = fasync_helper(fd, file, on, &runtime->fasync); err = fasync_helper(fd, file, on, &runtime->fasync);
out: out:
unlock_kernel(); unlock_kernel();
if (err < 0) return err;
return err;
return 0;
} }
/* /*
......
...@@ -1825,13 +1825,9 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, ...@@ -1825,13 +1825,9 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
static int snd_timer_user_fasync(int fd, struct file * file, int on) static int snd_timer_user_fasync(int fd, struct file * file, int on)
{ {
struct snd_timer_user *tu; struct snd_timer_user *tu;
int err;
tu = file->private_data; tu = file->private_data;
err = fasync_helper(fd, file, on, &tu->fasync); return fasync_helper(fd, file, on, &tu->fasync);
if (err < 0)
return err;
return 0;
} }
static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册