Received: by 10.223.176.5 with SMTP id f5csp976787wra; Sat, 3 Feb 2018 14:58:38 -0800 (PST) X-Google-Smtp-Source: AH8x2277teJ58IFzm16Zj23PLfIeRRDaCtOe7V6JuRIfnMweSOoSrvhGqaX3aX3gW31oFWyU4RnJ X-Received: by 10.101.83.3 with SMTP id m3mr1179949pgq.396.1517698718499; Sat, 03 Feb 2018 14:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517698718; cv=none; d=google.com; s=arc-20160816; b=z9maDLcsOf1Xrv5E4Hx0I3OwAWjlbzdQ5FlATM2uOdLZc4gHO8zfr7NsLhloNjmpvn Y4I/Pa9DKboWUY1AJyUogYheoOr+ddU36AdPk43wzYaznQqiU4Z/Qu3QmMDHsdjHzK69 4W4++Grk85AYXh09ys7x3X/vPXPB1xTTiODjdDlWOcnGP9hCHeYCsREeQDa6my3Z2J/u 8Wk3krh/nPL5DOWxhDzYSq1hok2UNXlInsClPmaIelCX5Yl7hQerm+ba9Ul4XM7jLodg ZOwe8a262LUbUr0trFxJDYMis/9JSfiF7eP8wx2yb3TydJ+RxVmlx302c9PhOu5CLcYp At+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=u4/QCJLjDkOEdQhojky/xf2JJAPxozBPW1reDsNpwi0=; b=QxJXkICdFvVczt2rIrIr4yhStr5m6hE2Naycn+F3BNeYcprZgPmwUlQKcAvmqcjPNA tliYQeRnShSMn8BpG9QVTJbt8CxXCcXv5exns4mRKaqgK8hQLACC3GDWryYOLjpQ+R9r PbhG69Wle7rrYfhTthY5f607PJ1Tqy9VlZ2GncX/wZzeYQEprq31Yk2/12lLbh7yV5vu wbrC9WIJgSDB/GgigvMI6ZqgV9+348zYiYxm5WA6oAT/FXYQRefTScmBxWPvfY7o5vjo 67gSeHftK3ZPNqeBQ6Pfsji0KibR7r1oFZG9TsbEOh8d1xeNs9Z9LZ64VPjMNAQsGLxg fuaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=MGeGks6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10-v6si2180071plo.820.2018.02.03.14.58.24; Sat, 03 Feb 2018 14:58:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=MGeGks6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754830AbeBCSw7 (ORCPT + 99 others); Sat, 3 Feb 2018 13:52:59 -0500 Received: from mail-bl2nam02on0134.outbound.protection.outlook.com ([104.47.38.134]:35168 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752838AbeBCSBD (ORCPT ); Sat, 3 Feb 2018 13:01:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=u4/QCJLjDkOEdQhojky/xf2JJAPxozBPW1reDsNpwi0=; b=MGeGks6RyEhk5zCOo7N1DFp01SD6sSWJRQiR7NrSrFKDpQoHR3CpmX8j6f9+iCbIaa+BSBvZmMnqMXs/4fI9JYtpMxaIDxEASjBkNSwUvce1HX/q+pxGG8r9iDRIu5RI9i3Zizq5nVK/esa5ktRAedk4dHU9SZtY3Mio7mFHTPI= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1090.namprd21.prod.outlook.com (52.132.24.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.1; Sat, 3 Feb 2018 18:00:41 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:00:41 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Hannes Reinecke , Hannes Reinecke , "Martin K . Petersen" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 024/110] scsi: core: check for device state in __scsi_remove_target() Thread-Topic: [PATCH AUTOSEL for 4.14 024/110] scsi: core: check for device state in __scsi_remove_target() Thread-Index: AQHTnRjmsOcnDB1qIkKhePoAB6WrTA== Date: Sat, 3 Feb 2018 18:00:39 +0000 Message-ID: <20180203180015.29073-24-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1090;6:77zdUZ1lDhtp8+Tf8kZXao5nN6whxcJX76s1AWueGIdA3RDJy9P3WOnqvJGoeS9aac5W4+HJ8skMbD3PkJlI/1rfS1HwGSXnpwMvxS2hdgTuum/JX/pP2D/5guz/h3UWlno2t/kMjhx/C0v/AUKZDNp/iSXhrD2eEoVICaJOCphSYVaARBZX+q2M0/Jc9KCyEVyYDcoL4057R1UrC2SjET7mvIPCUkwz2PmfJEzz8lslSZipBhGdNTkT/bWEKfy4MdZvD0Nbdoi20MCiKtlT3vRiL5PCsoNk6aBslcX6and6qKxCkbORpA2bNbMlD1p6kKh6DdgOw59QLTLND78e+ntoJ8dJSDohcoNGiB5qtu1qmXM56ayIXqZq+/J3yjlt;5:6CuPIkHeMs8brbsBdraumyNLuoOG1Es58n78F9qtbDiIWOsRvIedvV2gMSginEQq9Zn+jZB/li2fS+sfhad2fmRl0u2HmVC3GFa6Hred1/ZemFNMxuVjVT2ksoiMPcfWoM5j5l7Dj9wKxHJ1+MB8qejaY3g8sLDEC9e1eT4tld4=;24:CvmoaURNm9NMQu5k6DryK5mTa4SG1tXGQ1vrtPrcplT4XoFNBzMthYWSBKTXw5VRxkV78Z5+Y1x/3OfqShH9JVZWJaB3yRBcbpSkVpybN0M=;7:J6dAyoLdi28395JRyI23Z3WjqUjtu1aH2RMiaOaTth2bPCxDzBsp6SRPXb8nZkag4pN3cRhFiQW+gi6AQx7PYtKonVEC33tw+gFaD+HwbRW7FEp/eg1NilZbGJMnMS0dR1nop9BFsaHIWLXL5pxGQpmdMZ3vq5+5biuy/2h4IGYBeQSNpGR/dbiWdD3xY7zr4+INzJMLpRPuMnqSOzwRsMtNnHPAwHw1Df5lcg8ltJW2/yGKmRrtH0CrWwPdxOYv x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 53145365-1764-4686-78b0-08d56b300a5a x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1090; x-ms-traffictypediagnostic: BL0PR2101MB1090: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(50582790962513)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BL0PR2101MB1090;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1090; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(396003)(39380400002)(39860400002)(346002)(199004)(189003)(2900100001)(5660300001)(316002)(25786009)(4326008)(14454004)(2950100002)(478600001)(575784001)(107886003)(72206003)(22452003)(10290500003)(186003)(3660700001)(86612001)(76176011)(86362001)(53936002)(3280700002)(106356001)(6436002)(6486002)(59450400001)(81166006)(81156014)(2501003)(6506007)(97736004)(26005)(7736002)(6512007)(6346003)(102836004)(105586002)(68736007)(8936002)(5250100002)(305945005)(36756003)(1076002)(6116002)(3846002)(8676002)(110136005)(66066001)(54906003)(2906002)(10090500001)(99286004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1090;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: dMYwWXwIqG45cgfUvgO+LMNtKXrEiVDnbgyY9MwhuM8Lt3X+Ea32wtbgR7QirNDgluPxkPenoPSpLNsxVHyzOw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53145365-1764-4686-78b0-08d56b300a5a X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:39.5346 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hannes Reinecke [ Upstream commit 81b6c999897919d5a16fedc018fe375dbab091c5 ] As it turned out device_get() doesn't use kref_get_unless_zero(), so we will be always getting a device pointer. Consequently, we need to check for the device state in __scsi_remove_target() to avoid tripping over deleted objects. Fixes: fbce4d97fd43 ("scsi: fixup kernel warning during rmmod()") Reported-by: Jason Yan Signed-off-by: Hannes Reinecke Reviewed-by: Bart Van Assche Reviewed-by: Ewan D. Milne Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index f796bd61f3f0..40406c162d0d 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1383,7 +1383,10 @@ static void __scsi_remove_target(struct scsi_target = *starget) * check. */ if (sdev->channel !=3D starget->channel || - sdev->id !=3D starget->id || + sdev->id !=3D starget->id) + continue; + if (sdev->sdev_state =3D=3D SDEV_DEL || + sdev->sdev_state =3D=3D SDEV_CANCEL || !get_device(&sdev->sdev_gendev)) continue; spin_unlock_irqrestore(shost->host_lock, flags); --=20 2.11.0