Skip to contentSkip to conversation

staging: rdma: hfi1: Fix return type

PATCH In review Bhaktipriya Shridhar 2 participants 2 messages Feb 24, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rdma: hfi1: Fix return type

This function can return negative values (-ENODEV). Hence its type has been replaced from unsigned int to signed int.

The only occurrence of this function is in structure file_operations snoop_file_ops as .poll = hfi1_snoop_poll

This was done using Coccinelle.

@@ identifier f; constant C;@@
unsigned int f (...){
<+...
* return -C;
...+>
}

---
 drivers/staging/rdma/hfi1/diag.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/rdma/hfi1/diag.c +2 -4
index e41159f..bc0fb0b 100644
@@ -206,8 +206,7 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data,
 static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
 				size_t count, loff_t *off);
 static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
-static unsigned int hfi1_snoop_poll(struct file *fp,
-				    struct poll_table_struct *wait);
+static int hfi1_snoop_poll(struct file *fp, struct poll_table_struct *wait);
 static int hfi1_snoop_release(struct inode *in, struct file *fp);
 
 struct hfi1_packet_filter_command {
@@ -790,8 +789,7 @@ static int hfi1_snoop_release(struct inode *in, struct file *fp)
 	return 0;
 }
 
-static unsigned int hfi1_snoop_poll(struct file *fp,
-				    struct poll_table_struct *wait)
+static int hfi1_snoop_poll(struct file *fp, struct poll_table_struct *wait)
 {
 	int ret = 0;
 	unsigned long flags = 0;

--
2.1.4

#1 lore raw
Quoted 5 lines · Bhaktipriya Shridhar

This function can return negative values (-ENODEV). Hence its type has been replaced from unsigned int to signed int.

The only occurrence of this function is in structure file_operations snoop_file_ops as .poll = hfi1_snoop_poll

Doesn't this give a compiler error, because the poll field is declared as being a function with return type unsigned int?

Whether the negative value is valid ultimately depends on where it is consumed. I don't know where it is consumed for hfi1_snoop_poll, but below are the places that I could find that a file_operations poll value is called. Some seem to be for specific drivers. For the ones that look more generic, such as ep_item_poll in fs/eventpoll.c, the result is immediately bit anded with some other value, with no check for an error value. So it looks like giving an error code could produce unexpected results.

julia

(in the following - indicates a line of interest, not a suggestion to remove something.)

tmp/nothing/drivers/vfio/virqfd.c renamed from var/linuxes/linux-next/drivers/vfio/virqfd.c +0 -1
diff -u -p /var/linuxes/linux-next/drivers/vfio/virqfd.c /tmp/nothing/drivers/vfio/virqfd.c
@@ -166,7 +166,6 @@ int vfio_virqfd_enable(void *opaque,
 	init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
 	init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
 
-	events = irqfd.file->f_op->poll(irqfd.file, &virqfd->pt);
 
 	/*
 	 * Check if there was an event already pending on the eventfd
tmp/nothing/drivers/staging/comedi/drivers/serial2002.c renamed from var/linuxes/linux-next/drivers/staging/comedi/drivers/serial2002.c +0 -1
diff -u -p /var/linuxes/linux-next/drivers/staging/comedi/drivers/serial2002.c /tmp/nothing/drivers/staging/comedi/drivers/serial2002.c
@@ -129,7 +129,6 @@ static void serial2002_tty_read_poll_wai
 		long elapsed;
 		int mask;
 
-		mask = f->f_op->poll(f, &table.pt);
 		if (mask & (POLLRDNORM | POLLRDBAND | POLLIN |
 			    POLLHUP | POLLERR)) {
 			break;
tmp/nothing/drivers/vhost/vhost.c renamed from var/linuxes/linux-next/drivers/vhost/vhost.c +0 -1
diff -u -p /var/linuxes/linux-next/drivers/vhost/vhost.c /tmp/nothing/drivers/vhost/vhost.c
@@ -169,7 +169,6 @@ int vhost_poll_start(struct vhost_poll *
 	if (poll->wqh)
 		return 0;
 
-	mask = file->f_op->poll(file, &poll->table);
 	if (mask)
 		vhost_poll_wakeup(&poll->wait, 0, 0, (void *)mask);
 	if (mask & POLLERR) {
tmp/nothing/fs/eventpoll.c renamed from var/linuxes/linux-next/fs/eventpoll.c +0 -1
diff -u -p /var/linuxes/linux-next/fs/eventpoll.c /tmp/nothing/fs/eventpoll.c
@@ -802,7 +802,6 @@ static inline unsigned int ep_item_poll(
 {
 	pt->_key = epi->event.events;
 
-	return epi->ffd.file->f_op->poll(epi->ffd.file, pt) & epi->event.events;
 }
 
 static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
tmp/nothing/fs/select.c renamed from var/linuxes/linux-next/fs/select.c +0 -1
diff -u -p /var/linuxes/linux-next/fs/select.c /tmp/nothing/fs/select.c
@@ -764,7 +764,6 @@ static inline unsigned int do_pollfd(str
 			if (f.file->f_op->poll) {
 				pwait->_key = pollfd->events|POLLERR|POLLHUP;
 				pwait->_key |= busy_flag;
-				mask = f.file->f_op->poll(f.file, pwait);
 				if (mask & busy_flag)
 					*can_busy_poll = true;
 			}
tmp/nothing/fs/aio.c renamed from var/linuxes/linux-next/fs/aio.c +0 -1
diff -u -p /var/linuxes/linux-next/fs/aio.c /tmp/nothing/fs/aio.c
@@ -1679,7 +1679,6 @@ static long aio_thread_op_poll(struct ai
 		mask = DEFAULT_POLLMASK;
 		if (file->f_op && file->f_op->poll) {
 			table.pt._key = events;
-			mask = file->f_op->poll(file, &table.pt);
 		}
 		/* Mask out unneeded events. */
 		mask &= events;
tmp/nothing/mm/memcontrol.c renamed from var/linuxes/linux-next/mm/memcontrol.c +0 -1
diff -u -p /var/linuxes/linux-next/mm/memcontrol.c /tmp/nothing/mm/memcontrol.c
@@ -3881,7 +3881,6 @@ static ssize_t memcg_write_event_control
 	if (ret)
 		goto out_put_css;
 
-	efile.file->f_op->poll(efile.file, &event->pt);
 
 	spin_lock(&memcg->event_list_lock);
 	list_add(&event->list, &memcg->event_list);
tmp/nothing/net/9p/trans_fd.c renamed from var/linuxes/linux-next/net/9p/trans_fd.c +0 -2
diff -u -p /var/linuxes/linux-next/net/9p/trans_fd.c /tmp/nothing/net/9p/trans_fd.c
@@ -242,12 +242,10 @@ p9_fd_poll(struct p9_client *client, str
 	if (!ts->wr->f_op->poll)
 		return -EIO;
 
-	ret = ts->rd->f_op->poll(ts->rd, pt);
 	if (ret < 0)
 		return ret;
 
 	if (ts->rd != ts->wr) {
-		n = ts->wr->f_op->poll(ts->wr, pt);
 		if (n < 0)
 			return n;
 		ret = (ret & ~POLLOUT) | (n & ~POLLIN);
tmp/nothing/virt/kvm/eventfd.c renamed from var/linuxes/linux-next/virt/kvm/eventfd.c +0 -1
diff -u -p /var/linuxes/linux-next/virt/kvm/eventfd.c /tmp/nothing/virt/kvm/eventfd.c
@@ -397,7 +397,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct
 	 * Check if there was an event already pending on the eventfd
 	 * before we registered, and trigger it as if we didn't miss it.
 	 */
-	events = f.file->f_op->poll(f.file, &irqfd->pt);
 
 	if (events & POLLIN)
 		schedule_work(&irqfd->inject);