From patchwork Wed Sep 9 07:02:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Xue X-Patchwork-Id: 7144771 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1BB9E9F32B for ; Wed, 9 Sep 2015 07:22:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1677E2086F for ; Wed, 9 Sep 2015 07:22:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65AC42086E for ; Wed, 9 Sep 2015 07:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751557AbbIIHWf (ORCPT ); Wed, 9 Sep 2015 03:22:35 -0400 Received: from mail-bn1on0099.outbound.protection.outlook.com ([157.56.110.99]:18974 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751082AbbIIHWe (ORCPT ); Wed, 9 Sep 2015 03:22:34 -0400 Received: from BN1PR12CA0015.namprd12.prod.outlook.com (10.160.77.25) by DM3PR12MB0859.namprd12.prod.outlook.com (10.164.7.141) with Microsoft SMTP Server (TLS) id 15.1.262.15; Wed, 9 Sep 2015 07:06:32 +0000 Received: from BY2NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::201) by BN1PR12CA0015.outlook.office365.com (2a01:111:e400:49::25) with Microsoft SMTP Server (TLS) id 15.1.262.15 via Frontend Transport; Wed, 9 Sep 2015 07:06:32 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=amd.com; intel.com; dkim=none (message not signed) header.d=none; intel.com; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp02.amd.com (165.204.84.222) by BY2NAM03FT005.mail.protection.outlook.com (10.152.84.94) with Microsoft SMTP Server id 15.1.274.4 via Frontend Transport; Wed, 9 Sep 2015 07:06:31 +0000 X-WSS-ID: 0NUEEES-08-2G9-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 25658D16042; Wed, 9 Sep 2015 03:06:28 -0400 (EDT) Received: from SATLEXDAG03.amd.com (10.181.40.7) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 9 Sep 2015 02:06:50 -0500 Received: from SCYBEXDAG04.amd.com (10.34.11.14) by satlexdag03.amd.com (10.181.40.7) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 9 Sep 2015 03:06:30 -0400 Received: from [10.237.74.14] (10.237.74.14) by SCYBEXDAG04.amd.com (10.34.11.14) with Microsoft SMTP Server id 14.3.195.1; Wed, 9 Sep 2015 15:06:27 +0800 Message-ID: <1441782131.5845.73.camel@kxue-X58A-UD3R> Subject: [PATCH]SCSI:Refine the way to fix NULL pointer dereference in runtime PM From: Ken Xue To: CC: , , , , , Date: Wed, 9 Sep 2015 15:02:11 +0800 X-Mailer: Evolution 3.10.4-0ubuntu2 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(23433003)(199003)(189002)(50466002)(47776003)(50226001)(2351001)(19580395003)(189998001)(106466001)(229853001)(33646002)(101416001)(4001540100001)(103116003)(11100500001)(5001830100001)(110136002)(5001860100001)(50986999)(46102003)(87936001)(23676002)(19580405001)(97736004)(2171001)(33716001)(77156002)(62966003)(5820100001)(105586002)(68736005)(64706001)(5007970100001)(77096005)(86362001)(92566002)(99106002)(43043002)(3940600001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR12MB0859; H:atltwp02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0859; 2:E/rE/TDURn5rWrTK1oedpKKPeeldu+NW7rr70ByKRNmJUFgrioY+nVn4rbiD0nyclQyMioXerwpPNySsqbtknjJRdLfEvKa8APeCOw1jurIn61mjzxa+dPIzgIAyxd0GwlX5P+2Xdm074FDMd1fAxln5uCrpqEEds5es4yv4lM0=; 3:hM4Ywj0vOsLVSdbi1+4SZyZsThusGeX6obTgFrmmFY9XJpNPjCslbCkEdu6luMptgxeTSSa4i79mdzwKrei8khjjj9lgR20D6cMxS4D5gXRA9HZonc37ZBuYgOpOaE9/L4jyuwcet4prSoOk6qFbqocTFLYeR6VD+o+TFBjodMKZdyOOVczGTQGgjp6PPateWll1yU1GTqdBMrdLvZdx/6Fku2Xm5i/KhBVJCcUjwBN5hgqIKdzFcVWkbuDLhKq7; 25:kVN/n0tkoHni4K12kS9wG+nOkP+PYtj3cfGVhpHi/BgFNiHXOHO/pkJlPSI4LrooPMmSQOnY/morbikbqcPTAktUIh769I/7ZtpYa0H+GD6NkGDUZZ+dKun5fHyGjaXdo/GRuGsticdM6ZXzkVUBASRXmt5PQfuV0M46MSv0HD7wukI0/0l3ZRy/iGOS1YlOnzcB9qjJGZvx3r4ET43LnebMqZna+tKjM3l1WGUIj4pBJr+C9gDt10jfFLszT6YSBYlIm0YhIVcb0U6YbckJWg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM3PR12MB0859; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0859; 20:MtrTIdfDeacSi/Ak6qnxqvI/3o7Gaf6UPjr1gKBOhMExLpUa2Szfq25CZDhjhOXrXsdD+37Ab3UkvzpGdnOI2G6FWxkAVFiB8vajpNFpuczNWpj081r4VGXPPkSjYt7pFp72sErHlVptAAI+dy1g7kJvlWLrBukek9/3BGBs4GyuSBBHNZ1ToYMTbtfWMOMxjqR3og2T74x8IQ3Ae4o56fVQCQG07kZsix1ANGHYXNDUy5N9XU0o9gECKAeFXjciQ+Ef9TN4jtgvPyNvAx006pI4E1jbn93B7Qj7KdJDJXqkBo9xHtteq9GjHPvnM8tZU6NWegGib0RUfLVk743ADxnAvLwDFJFRcHEXurbCIfCl6TKwsjpJ9m3xFWkmD1dvPx8+bEuBDjkHjS2V0bHXSOrKYbu1TiErKVRU4MEKc7Cb6OK4ykG5OqZVS6ExxeRKQYOpA7Q8/t1f/sBvjxmhFsq3SKSOPpunC2l4BrtNyVOr94K0ZVHok+X0PdLhFnNM; 4:UiYKYq0ajcOvyggc2CEvO5sN8GoPKHhZD73cs3+ouQgUF3g4Cn21hvtJQ8h8fcul78ZenAopq76N/eUOc4yK20kTSHQQEfYMyuuosdN8ifpVLJZ2To1v6WyL/vIKhBVvSZWAsq4pnB2CItbZfWZj710K9zFa9MO5Gs/s3/T3GcoCnOK10nKBsPc5EHlbRxEvTHZUYXW5jq9dok0c+bDHWkrLoYfEGVFKTKU6w8lcTHvGu0b4ljscX1u0ZKCrp/JUnNXNOpXYL6iwr6z2XW2ePup5po9OvWG6a1m2OQfsdp/ILNS5UcyefCJmzdz+TS18 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(5005006)(3002001); SRVR:DM3PR12MB0859; BCL:0; PCL:0; RULEID:; SRVR:DM3PR12MB0859; X-Forefront-PRVS: 0694C54398 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTNQUjEyTUIwODU5OzIzOk5zbUhjdUhzTVhVSnZoZ1hDQTZncXFZN3g2?= =?utf-8?B?b2M4QTlaZ0NkS3J5WUVWR20ydWhmK0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ki68QkLy9FhSbCR98gcBUDA1j7eUxg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2015 07:06:31.9983 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.222]; Helo=[atltwp02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB0859 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From 844ebfcecad7ddaf7206e0474c600b0146b4ef21 Mon Sep 17 00:00:00 2001 From: Ken Xue Date: Wed, 9 Sep 2015 14:55:21 +0800 Subject: [PATCH] SCSI:Refine the way to fix NULL pointer dereference in runtime PM There was a patch about Bugzilla #101371. That patch introduced a possibility that can not call blk_{pre|post}_runtime_suspend and blk_{pre|post}_runtime_resume in pairs. Signed-off-by: Ken Xue Acked-by: Alan Stern --- block/blk-core.c | 12 ++++++++++++ drivers/scsi/scsi_pm.c | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 60912e9..a07ab18 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3280,6 +3280,9 @@ int blk_pre_runtime_suspend(struct request_queue *q) { int ret = 0; + if (!q->dev) + return ret; + spin_lock_irq(q->queue_lock); if (q->nr_pending) { ret = -EBUSY; @@ -3307,6 +3310,9 @@ EXPORT_SYMBOL(blk_pre_runtime_suspend); */ void blk_post_runtime_suspend(struct request_queue *q, int err) { + if (!q->dev) + return; + spin_lock_irq(q->queue_lock); if (!err) { q->rpm_status = RPM_SUSPENDED; @@ -3331,6 +3337,9 @@ EXPORT_SYMBOL(blk_post_runtime_suspend); */ void blk_pre_runtime_resume(struct request_queue *q) { + if (!q->dev) + return; + spin_lock_irq(q->queue_lock); q->rpm_status = RPM_RESUMING; spin_unlock_irq(q->queue_lock); @@ -3353,6 +3362,9 @@ EXPORT_SYMBOL(blk_pre_runtime_resume); */ void blk_post_runtime_resume(struct request_queue *q, int err) { + if (!q->dev) + return; + spin_lock_irq(q->queue_lock); if (!err) { q->rpm_status = RPM_ACTIVE; diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index e4b7998..459abe1 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -219,13 +219,13 @@ static int sdev_runtime_suspend(struct device *dev) struct scsi_device *sdev = to_scsi_device(dev); int err = 0; - if (pm && pm->runtime_suspend) { - err = blk_pre_runtime_suspend(sdev->request_queue); - if (err) - return err; + err = blk_pre_runtime_suspend(sdev->request_queue); + if (err) + return err; + if (pm && pm->runtime_suspend) err = pm->runtime_suspend(dev); - blk_post_runtime_suspend(sdev->request_queue, err); - } + blk_post_runtime_suspend(sdev->request_queue, err); + return err; } @@ -248,11 +248,11 @@ static int sdev_runtime_resume(struct device *dev) const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int err = 0; - if (pm && pm->runtime_resume) { - blk_pre_runtime_resume(sdev->request_queue); + blk_pre_runtime_resume(sdev->request_queue); + if (pm && pm->runtime_resume) err = pm->runtime_resume(dev); - blk_post_runtime_resume(sdev->request_queue, err); - } + blk_post_runtime_resume(sdev->request_queue, err); + return err; }