linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christian Löhle" <CLoehle@hyperstone.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"axboe@kernel.dk" <axboe@kernel.dk>,
	"Christian Löhle" <CLoehle@hyperstone.com>
Subject: [PATCH] block: prevent sending events from removed device
Date: Wed, 30 Jun 2021 08:09:39 +0000	[thread overview]
Message-ID: <CWXP265MB2680EBAF4FEE64FBE80FAF25C4019@CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM> (raw)

Skip kobject_uevent_env in case the associated kobject
no longer exists, as calling kobject_uevent_env with
NULL is not safe.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
 block/genhd.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 9f8cb7beaad1..46629fbe23ae 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1655,8 +1655,16 @@ static void disk_check_events(struct disk_events *ev,
 		    (disk->event_flags & DISK_EVENT_FLAG_UEVENT))
 			envp[nr_events++] = disk_uevents[i];
 
-	if (nr_events)
-		kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
+	if (nr_events) {
+		struct kobject *dev_kobj = kobject_get(&disk_to_dev(disk)->kobj);
+		/* The device kobject might have been removed in the
+		 * meantime, so check for it first.
+		 * If it was removed there is no need to signal events
+		 */
+		if (!dev_kobj)
+			kobject_uevent_env(dev_kobj, KOBJ_CHANGE, envp);
+		kobject_put(dev_kobj);
+	}
 }
 
 /*
-- 
2.32.0

Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz
Managing Directors: Dr. Jan Peter Berns.
Commercial register of local courts: Freiburg HRB381782


             reply	other threads:[~2021-06-30  8:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  8:09 Christian Löhle [this message]
2021-06-30 11:46 ` [PATCHv2] block: prevent sending events from removed device Christian Löhle
2021-07-01  7:42 ` [PATCH] " Christoph Hellwig
2021-07-01  8:23   ` Christian Löhle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CWXP265MB2680EBAF4FEE64FBE80FAF25C4019@CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM \
    --to=cloehle@hyperstone.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).