Skip to contentSkip to conversation

misc: xilinx_sdfec: fix xsdfec_poll()'s return type

PATCH Superseded Luc Van Oostenryck 2 participants 5 messages Nov 20, 2019 – Nov 21, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: xilinx_sdfec: fix xsdfec_poll()'s return type

xsdfec_poll() is defined as returning 'unsigned int' but the .poll method is declared as returning '__poll_t', a bitwise type.

Fix this by using the proper return type and using the EPOLL constants instead of the POLL ones, as required for __poll_t.

CC Derek Kiernan <[email protected]>
CC Dragan Cvetic <[email protected]>
---
 drivers/misc/xilinx_sdfec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/misc/xilinx_sdfec.c +5 -5
index 11835969e982..48ba7e02bed7 100644
@@ -1025,25 +1025,25 @@ static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd,
 }
 #endif
 
-static unsigned int xsdfec_poll(struct file *file, poll_table *wait)
+static __poll_t xsdfec_poll(struct file *file, poll_table *wait)
 {
-	unsigned int mask = 0;
+	__poll_t mask = 0;
 	struct xsdfec_dev *xsdfec;
 
 	xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
 
 	if (!xsdfec)
-		return POLLNVAL | POLLHUP;
+		return EPOLLNVAL | EPOLLHUP;
 
 	poll_wait(file, &xsdfec->waitq, wait);
 
 	/* XSDFEC ISR detected an error */
 	spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
 	if (xsdfec->state_updated)
-		mask |= POLLIN | POLLPRI;
+		mask |= EPOLLIN | EPOLLPRI;
 
 	if (xsdfec->stats_updated)
-		mask |= POLLIN | POLLRDNORM;
+		mask |= EPOLLIN | EPOLLRDNORM;
 	spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
 
 	return mask;
Signature · 1 line
2.24.0
#1 lore raw

Hi Luc,

For the sake of my understanding I'd like to ask you when the .pole method is defined
Why I'm asking this? I have a fairly new book (published in 2017) which suggests what is implemented in SDFEC driver.

I'll test your suggestions and will come back to you soon.

Regards
Dragan

Quoted 58 lines

-----Original Message-----
From: Luc Van Oostenryck [mailto:[email protected]]
Sent: Wednesday 20 November 2019 00:11
To: [email protected]
Cc: Luc Van Oostenryck <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Subject: [PATCH] misc: xilinx_sdfec: fix xsdfec_poll()'s return type

xsdfec_poll() is defined as returning 'unsigned int' but the .poll method is declared as returning '__poll_t', a bitwise type.

Fix this by using the proper return type and using the EPOLL constants instead of the POLL ones, as required for __poll_t.

CC Derek Kiernan <[email protected]>
CC Dragan Cvetic <[email protected]>
---
 drivers/misc/xilinx_sdfec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/misc/xilinx_sdfec.c +5 -6
index 11835969e982..48ba7e02bed7 100644
@@ -1025,25 +1025,25 @@ static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd,
 }
 #endif
 
-static unsigned int xsdfec_poll(struct file *file, poll_table *wait)
+static __poll_t xsdfec_poll(struct file *file, poll_table *wait)
 {
-	unsigned int mask = 0;
+	__poll_t mask = 0;
 	struct xsdfec_dev *xsdfec;
 
 	xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
 
 	if (!xsdfec)
-		return POLLNVAL | POLLHUP;
+		return EPOLLNVAL | EPOLLHUP;
 
 	poll_wait(file, &xsdfec->waitq, wait);
 
 	/* XSDFEC ISR detected an error */
 	spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
 	if (xsdfec->state_updated)
-		mask |= POLLIN | POLLPRI;
+		mask |= EPOLLIN | EPOLLPRI;
 
 	if (xsdfec->stats_updated)
-		mask |= POLLIN | POLLRDNORM;
+		mask |= EPOLLIN | EPOLLRDNORM;
 	spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
 
 	return mask;
--

2.24.0

#2 lore raw
Quoted 6 lines · Dragan Cvetic

Hi Luc,

For the sake of my understanding I'd like to ask you when the .pole method is defined
Why I'm asking this? I have a fairly new book (published in 2017) which suggests what is implemented in SDFEC driver.

I'll test your suggestions and will come back to you soon.

Well, yes, it changed in July 2017.

The current definition can be found in include/linux/fs.h:

	struct file_operations {
		...
		__poll_t (*poll) (struct file *, struct poll_table_struct *);
		...

The main commit making the change is:

    a3f8683bf7d5 ("->poll() methods should return __poll_t")

The result can be verified by compiling the driver with the command
make C=2 path/to/the/driver.o
which will use the static analyser 'sparse' to make additional checks where the difference between 'unsigned int' and __poll_t will matter. See Documentation/dev-tools/sparse.rst for more info about it.

Best regards,
-- Luc Van Oostenryck

#3 lore raw

Hi Luc,

Thanks for the really useful answer.

I promise I'll test this soon.

Thanks
Dragan

Quoted 35 lines

-----Original Message-----
From: Luc Van Oostenryck [mailto:[email protected]]
Sent: Wednesday 20 November 2019 18:02
To: Dragan Cvetic <[email protected]>
Cc: [email protected]; Derek Kiernan <[email protected]>
Subject: Re: [PATCH] misc: xilinx_sdfec: fix xsdfec_poll()'s return type

Quoted 6 lines · Dragan Cvetic

Hi Luc,

For the sake of my understanding I'd like to ask you when the .pole method is defined
Why I'm asking this? I have a fairly new book (published in 2017) which suggests what is implemented in SDFEC driver.

I'll test your suggestions and will come back to you soon.

Well, yes, it changed in July 2017.

The current definition can be found in include/linux/fs.h:

	struct file_operations {
		...
		__poll_t (*poll) (struct file *, struct poll_table_struct *);
		...

The main commit making the change is:

    a3f8683bf7d5 ("->poll() methods should return __poll_t")

The result can be verified by compiling the driver with the command
make C=2 path/to/the/driver.o
which will use the static analyser 'sparse' to make additional checks where the difference between 'unsigned int' and __poll_t will matter. See Documentation/dev-tools/sparse.rst for more info about it.

Best regards,
-- Luc Van Oostenryck

Acked-by on v1 1/1
#4 lore raw
In reply to Luc Van Oostenryck

Hi Luc,

please find my comments below.

Quoted 57 lines

-----Original Message-----
From: Luc Van Oostenryck [mailto:[email protected]]
Sent: Wednesday 20 November 2019 00:11
To: [email protected]
Cc: Luc Van Oostenryck <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>
Subject: [PATCH] misc: xilinx_sdfec: fix xsdfec_poll()'s return type

xsdfec_poll() is defined as returning 'unsigned int' but the .poll method is declared as returning '__poll_t', a bitwise type.

Fix this by using the proper return type and using the EPOLL constants instead of the POLL ones, as required for __poll_t.

CC Derek Kiernan <[email protected]>
CC Dragan Cvetic <[email protected]>
---
 drivers/misc/xilinx_sdfec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/misc/xilinx_sdfec.c +5 -6
index 11835969e982..48ba7e02bed7 100644
@@ -1025,25 +1025,25 @@ static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd,
 }
 #endif
 
-static unsigned int xsdfec_poll(struct file *file, poll_table *wait)
+static __poll_t xsdfec_poll(struct file *file, poll_table *wait)
 {
-	unsigned int mask = 0;
+	__poll_t mask = 0;
 	struct xsdfec_dev *xsdfec;
 
 	xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
 
 	if (!xsdfec)
-		return POLLNVAL | POLLHUP;
+		return EPOLLNVAL | EPOLLHUP;
 
 	poll_wait(file, &xsdfec->waitq, wait);
 
 	/* XSDFEC ISR detected an error */
 	spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
 	if (xsdfec->state_updated)
-		mask |= POLLIN | POLLPRI;
+		mask |= EPOLLIN | EPOLLPRI;
 
 	if (xsdfec->stats_updated)
-		mask |= POLLIN | POLLRDNORM;
+		mask |= EPOLLIN | EPOLLRDNORM;
 	spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
 
 	return mask;
--
Quoted 1 line

2.24.0