From patchwork Wed Jun 30 08:09:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Loehle X-Patchwork-Id: 12351567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 230AEC11F68 for ; Wed, 30 Jun 2021 08:16:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02E2361D06 for ; Wed, 30 Jun 2021 08:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233230AbhF3ISd convert rfc822-to-8bit (ORCPT ); Wed, 30 Jun 2021 04:18:33 -0400 Received: from de-smtp-delivery-105.mimecast.com ([194.104.109.105]:48530 "EHLO de-smtp-delivery-105.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232954AbhF3ISd (ORCPT ); Wed, 30 Jun 2021 04:18:33 -0400 X-Greylist: delayed 303 seconds by postgrey-1.27 at vger.kernel.org; Wed, 30 Jun 2021 04:18:32 EDT Received: from GBR01-CWL-obe.outbound.protection.outlook.com (mail-cwlgbr01lp2058.outbound.protection.outlook.com [104.47.20.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-12-Dc0_KYCqOtCL84aVUVYo6g-1; Wed, 30 Jun 2021 10:09:40 +0200 X-MC-Unique: Dc0_KYCqOtCL84aVUVYo6g-1 Received: from CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:89::10) by CWLP265MB2580.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:a7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18; Wed, 30 Jun 2021 08:09:39 +0000 Received: from CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM ([fe80::259d:65ac:ae6d:409d]) by CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM ([fe80::259d:65ac:ae6d:409d%9]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 08:09:39 +0000 From: =?iso-8859-1?q?Christian_L=F6hle?= To: "linux-kernel@vger.kernel.org" , "linux-block@vger.kernel.org" , "axboe@kernel.dk" , =?iso-8859-1?q?Christian_L=F6hle?= Subject: [PATCH] block: prevent sending events from removed device Thread-Topic: [PATCH] block: prevent sending events from removed device Thread-Index: AQHXbYcPaY+gyAaNCEO3EseEwW+vDg== Date: Wed, 30 Jun 2021 08:09:39 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [185.80.168.10] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ff1c51c8-8fb8-4e12-cf00-08d93b9e68c7 x-ms-traffictypediagnostic: CWLP265MB2580: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0 x-microsoft-antispam-message-info: dc5GgzqLci+Or4h5A27tJsXx+F034tg90MvyaZLDRzjIfsYcs+M/Ooesb4xwEVKU6ZtzZIXeSKkZUoCvEp59AmyY2yDDCnYid2/DPd4TYipAr/DDWsDzi1aZCLMdMoIjt3ijtoA5exXRBphAg2t9jAlIO5pAi0GAyw/hq2ywWaSc/D7AZruQWT0pbOnZvuuOZwrqLRyPo0JNabfpOTB++sRcR+q8TDvVTVs8NveWMhsORk9pptYyBigaq2WAR8dBIFZw659QR/rqTmt2eLnr3esFvNWR8AUrN8AoDSQ7C3Pd85jMubNGix/xrv99WcpoQ1zaJ5EqzroWwJQTEkoiG+v+Gt+EJ24PN7EWnPpCZEfeZEIz39OjiczMAmCIyueZ4Z/vSKi1cxRxsAbI6SkfzRl8828DAwab8Uj6OVJ8WMCPZjWsM8W6ywcbDzLV6e+z1tuvS7WYx/pulpR/rcZiUJUoHYEP1aClBE6raRxDYehGb2/KZ67/nkqHfjwE1mg4gjokWfbqIwnCsqzLXf5KV5RjS2FfqDVWD8X+d3GyuxUoikox2GcK98CXrIY0OZRdqJS8s1Np5kqAVo1kDGQQFgUcw2Je8YMl4kzpOu7pPVsBR9OCe+U6XBUV6Hr7URxHtiZglBSz1F3ciax4G9zfrg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(376002)(366004)(39840400004)(136003)(396003)(346002)(2906002)(52536014)(110136005)(8936002)(83380400001)(8676002)(316002)(64756008)(66476007)(91956017)(66946007)(76116006)(66556008)(66446008)(71200400001)(86362001)(6506007)(26005)(5660300002)(4744005)(33656002)(55016002)(9686003)(186003)(478600001)(38100700002)(7696005)(122000001);DIR:OUT;SFP:1101 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?2CJvUtTdhsz5AI7VMbEmn+H?= =?iso-8859-1?q?gU4ma90M921B/1K1wWFPbIiy8QS+GEOtQigS2fCov/24tJwm64QLVsyjWxpD?= =?iso-8859-1?q?AAKmzHkVt44nY+QAqp3K9M9GacybJygHBAeDe1kASdTKiGYl1X32xkTwfObx?= =?iso-8859-1?q?u+MwZOkpgwq+2f3hXnVOCdobXNI04B5G0y1kZrfMaxJS/Kb5pZn5J6PRMlqE?= =?iso-8859-1?q?6+m+DJFax4apj5vRLzBW6ba+HhxImqDPwtIlqDjcW7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?= =?iso-8859-1?q?rVD52yWLPwwk8xRNSe02mKqDSUdVRs5xFW7rSYbG0LUYrluMxmQwaWO+fKeb?= =?iso-8859-1?q?+rwVv3dQgj706zlvYbUZq1SecVBETvy0EjaqWkdzo7ttFq7CnQ8kxFPVkMVc?= =?iso-8859-1?q?9vBI8d1Kd6RZr8ixFUILPrGiqwWA3NnAnkJ0WdDWzUGOqhw0+xQvQzkfiW77?= =?iso-8859-1?q?DZvdjPPK/m55k/FmO4elEKyXCgusv745oq5OLGP4=3D?= MIME-Version: 1.0 X-OriginatorOrg: hyperstone.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: ff1c51c8-8fb8-4e12-cf00-08d93b9e68c7 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jun 2021 08:09:39.7317 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 86f203eb-e878-4188-b297-34c118c18b11 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0vHi4OWiuLcZHP4bvmIuaxBzblSMFXbAEck3GmdfcAa19jZTqFDNakJ531nOXnwm4uH2GHd4fsfSB8COgmlpLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB2580 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: hyperstone.com Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 --- 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); + } } /*