All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] epoll: fix dereferenced before check pt
@ 2017-12-21 15:54 Vasyl Gomonovych
  2017-12-22  0:02 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Vasyl Gomonovych @ 2017-12-21 15:54 UTC (permalink / raw)
  To: viro, linux-fsdevel, gomonovych; +Cc: linux-kernel

This patch fixes the warning reported by smatch:

fs/eventpoll.c:889 ep_item_poll() warn: variable dereferenced before check 'pt'

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
---
 fs/eventpoll.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index afd548ebc328..fc772a1f1396 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -879,7 +879,8 @@ static unsigned int ep_item_poll(struct epitem *epi, poll_table *pt, int depth)
 	struct eventpoll *ep;
 	bool locked;
 
-	pt->_key = epi->event.events;
+	if (pt)
+		pt->_key = epi->event.events;
 	if (!is_file_epoll(epi->ffd.file))
 		return epi->ffd.file->f_op->poll(epi->ffd.file, pt) &
 		       epi->event.events;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] epoll: fix dereferenced before check pt
  2017-12-21 15:54 [PATCH] epoll: fix dereferenced before check pt Vasyl Gomonovych
@ 2017-12-22  0:02 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2017-12-22  0:02 UTC (permalink / raw)
  To: Vasyl Gomonovych; +Cc: linux-fsdevel, linux-kernel

On Thu, Dec 21, 2017 at 04:54:17PM +0100, Vasyl Gomonovych wrote:
> This patch fixes the warning reported by smatch:
> 
> fs/eventpoll.c:889 ep_item_poll() warn: variable dereferenced before check 'pt'

... and of course, that is all the analysis one might want - the tool has
spoken.  Except that the only thing proven is that the tool is either misused
or just plain crappy.

Callers of ep_item_poll() are easily found - it's static, so they all are in
the same file.  All four of them -
                if (ep_item_poll(epi, &pt, depth)) {
        revents = ep_item_poll(epi, &epq.pt, 1);
        if (ep_item_poll(epi, &pt, 1)) {
                revents = ep_item_poll(epi, &pt, 1);

Figuring out why an address of a local variable or of a field thereof can never
be NULL is left as an exercise for an introductory course on C.

"Fixing warnings" is bloody wrong - warning (from any tool) is a heuristic
pointing to a place that might be worth looking into.  In cases when you've
found a real problem with help from some tool, sure, go ahead and credit that
tool in the commit message.  Along with the description of the problem
you've found.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-22  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 15:54 [PATCH] epoll: fix dereferenced before check pt Vasyl Gomonovych
2017-12-22  0:02 ` Al Viro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.