mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] ipc/mqueue: Adjustments for do_mq_notify()
@ 2019-08-22 14:50 Markus Elfring
  2019-08-22 14:52 ` [PATCH 1/2] ipc/mqueue: Delete an unnecessary check before the macro call “dev_kfree_skb” Markus Elfring
  2019-08-22 14:54 ` [PATCH 2/2] ipc/mqueue: Improve exception handling in do_mq_notify() Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2019-08-22 14:50 UTC (permalink / raw)
  To: kernel-janitors, Al Viro, Andrew Morton, Arnd Bergmann,
	David Howells, Davidlohr Bueso, Kees Cook, Li Rongqing
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 22 Aug 2019 16:38:49 +0200
Subject: [PATCH 0/2] ipc/mqueue: Adjustments for do_mq_notify()

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an unnecessary check before the macro call “dev_kfree_skb”
  Improve exception handling in do_mq_notify()

 ipc/mqueue.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

--
2.23.0


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

* [PATCH 1/2] ipc/mqueue: Delete an unnecessary check before the macro call “dev_kfree_skb”
  2019-08-22 14:50 [PATCH 0/2] ipc/mqueue: Adjustments for do_mq_notify() Markus Elfring
@ 2019-08-22 14:52 ` Markus Elfring
  2019-08-22 14:54 ` [PATCH 2/2] ipc/mqueue: Improve exception handling in do_mq_notify() Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-08-22 14:52 UTC (permalink / raw)
  To: kernel-janitors, Al Viro, Andrew Morton, Arnd Bergmann,
	David Howells, Davidlohr Bueso, Kees Cook, Li Rongqing
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 22 Aug 2019 14:07:57 +0200

The dev_kfree_skb() function performs also input parameter validation.
Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 ipc/mqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 7a5a8edc3de3..494ab78863f4 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -1334,7 +1334,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
 out:
 	if (sock)
 		netlink_detachskb(sock, nc);
-	else if (nc)
+	else
 		dev_kfree_skb(nc);

 	return ret;
--
2.23.0


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

* [PATCH 2/2] ipc/mqueue: Improve exception handling in do_mq_notify()
  2019-08-22 14:50 [PATCH 0/2] ipc/mqueue: Adjustments for do_mq_notify() Markus Elfring
  2019-08-22 14:52 ` [PATCH 1/2] ipc/mqueue: Delete an unnecessary check before the macro call “dev_kfree_skb” Markus Elfring
@ 2019-08-22 14:54 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-08-22 14:54 UTC (permalink / raw)
  To: kernel-janitors, Al Viro, Andrew Morton, Arnd Bergmann,
	David Howells, Davidlohr Bueso, Kees Cook, Li Rongqing
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 22 Aug 2019 16:21:17 +0200

Null pointers were assigned to local variables in a few cases
as exception handling. The jump target “out” was used where no meaningful
data processing actions should eventually be performed by branches of
an if statement then.
Use an additional jump target for calling dev_kfree_skb() directly.

Return also directly after error conditions were detected when no extra
clean-up is needed by this function implementation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 ipc/mqueue.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 494ab78863f4..ad6c475eb370 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -1241,15 +1241,14 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)

 			/* create the notify skb */
 			nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
-			if (!nc) {
-				ret = -ENOMEM;
-				goto out;
-			}
+			if (!nc)
+				return -ENOMEM;
+
 			if (copy_from_user(nc->data,
 					notification->sigev_value.sival_ptr,
 					NOTIFY_COOKIE_LEN)) {
 				ret = -EFAULT;
-				goto out;
+				goto free_skb;
 			}

 			/* TODO: add a header? */
@@ -1265,8 +1264,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
 			fdput(f);
 			if (IS_ERR(sock)) {
 				ret = PTR_ERR(sock);
-				sock = NULL;
-				goto out;
+				goto free_skb;
 			}

 			timeo = MAX_SCHEDULE_TIMEOUT;
@@ -1275,11 +1273,8 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
 				sock = NULL;
 				goto retry;
 			}
-			if (ret) {
-				sock = NULL;
-				nc = NULL;
-				goto out;
-			}
+			if (ret)
+				return ret;
 		}
 	}

@@ -1335,6 +1330,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
 	if (sock)
 		netlink_detachskb(sock, nc);
 	else
+free_skb:
 		dev_kfree_skb(nc);

 	return ret;
--
2.23.0


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

end of thread, other threads:[~2019-08-22 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 14:50 [PATCH 0/2] ipc/mqueue: Adjustments for do_mq_notify() Markus Elfring
2019-08-22 14:52 ` [PATCH 1/2] ipc/mqueue: Delete an unnecessary check before the macro call “dev_kfree_skb” Markus Elfring
2019-08-22 14:54 ` [PATCH 2/2] ipc/mqueue: Improve exception handling in do_mq_notify() Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®