From patchwork Wed Nov 15 02:33:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10058609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D6DC6023A for ; Wed, 15 Nov 2017 02:35:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7047C298D2 for ; Wed, 15 Nov 2017 02:35:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64C11298DD; Wed, 15 Nov 2017 02:35:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D37298D2 for ; Wed, 15 Nov 2017 02:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754123AbdKOCfa (ORCPT ); Tue, 14 Nov 2017 21:35:30 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:42762 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbdKOCf2 (ORCPT ); Tue, 14 Nov 2017 21:35:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1510713329; x=1542249329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=XMdIWfSiCC/G1Y2CvgqLp25+QPOHHQxjnDsn9KPpodI=; b=l0IlTMb79O+Ww4Qub6hAz+ECRbMYpadObaIstGjJgm6Gfhdl5TGkVOpJ TotOPdAV7gsYEMnAglSUz4WdAkUDEMzP7eGqI67v59+ttqoBox4Ng456M 7W4xDVdZC+WuDeBONFbXT8dn/Vip3vI9wvwsZ3+zd0kl4Z5iadK8cOM2C U6EQf6+nZfxOQnky1ay4JRkk3EGpj60i5BBn9C5IOZJnepJg4PziftEbA I5YNXOxWGeqv4iPQ1zZTwV8AHnEswculUqIDwWotjP9/rvtKolOnTxFlG btW2cGI32CvK69tmPhl5+7KBp/a/8jA1mRTFpMHyB5i5P7ZUaP+WzchmD g==; X-IronPort-AV: E=Sophos;i="5.44,397,1505750400"; d="scan'208";a="62471981" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Nov 2017 10:35:28 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 14 Nov 2017 18:32:39 -0800 Received: from unknown (HELO MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip01.wdc.com with ESMTP; 14 Nov 2017 18:35:28 -0800 Received: from milsmgip11.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Tue, 14 Nov 2017 18:35:28 -0800 X-AuditID: 0ab10959-41c5898000002c97-ad-5a0ba7efff1f Received: from localhost.localdomain ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id E5.43.11415.FE7AB0A5; Tue, 14 Nov 2017 18:35:27 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" CC: , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , "Johannes Thumshirn" Subject: [PATCH 1/3] device information: Do not interpret error codes as flags Date: Tue, 14 Nov 2017 18:33:15 -0800 Message-ID: <20171115023317.3595-2-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115023317.3595-1-bart.vanassche@wdc.com> References: <20171115023317.3595-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOJMWRmVeSWpSXmKPExsXCtZEjRff9cu4ogwWL9S0u/fnCaLHgzV42 i5WrjzJZrJqYZ/G4awarRff1HWwWy4//Y3Jg93hwaDOLx+6bDWweH5/eYvFYv+Uqi8fm09Ue nzfJebQf6GYKYI/isklJzcksSy3St0vgynj6vKxgt17FhpMLGRsYf6h0MXJySAiYSOzpbGDu YuTiEBJYxCixYPUFZpAEm4CexKl5+5hAbBGBXIlTD28wgRQxC+xilPh27DYbSEJYwE/i/Mpn 7CA2i4CqxL3tfxi7GDk4eAWsJHo/pkAskJdY/H0nWDmngLXExD/7wcqFgErerv7GMoGRewEj wypGsdzMnOLc9MwCQ0O94sS8lMzibL3k/NxNjOCg4Yzcwfh0ovkhRiYOTqkGxiaTp4U9IccT V7FmMF108cvlqppxcYJaX3Td59NfOldUmcedff5kz/rrUh+9OPbabM7mtP9qnL+ltK3bsSYv r/+Y0vLN5xh5jX+Knl+y+WDfQemmAPaMv/MLLBW5av2NLmySUCiNuGGSGnOm9dcLQcbXXNeu mjY8n7rpMmtSJUswf4wdY1yeEktxRqKhFnNRcSIA1hggEcoBAAA= MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since commit 28a0bc4120d3 ("scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAP") bit 31 is a valid device information flag. Separate device information flags and return codes such that it becomes possible to check whether or not scsi_get_device_flags_keyed(). succeeded. This patch also avoids that error codes returned by scsi_get_device_flags_keyed() are interpret as device flags. Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn --- drivers/scsi/scsi_devinfo.c | 27 +++++++++++++++------------ drivers/scsi/scsi_priv.h | 6 ++++-- drivers/scsi/scsi_scan.c | 13 +++++++------ drivers/scsi/scsi_transport_spi.c | 7 ++++--- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c index fe5a9ea27b5e..e63873537139 100644 --- a/drivers/scsi/scsi_devinfo.c +++ b/drivers/scsi/scsi_devinfo.c @@ -564,6 +564,7 @@ static int scsi_dev_info_list_add_str(char *dev_list) * @sdev: &scsi_device to get flags for * @vendor: vendor name * @model: model name + * @flags: (output) device specific flags * * Description: * Search the global scsi_dev_info_list (specified by list zero) @@ -571,12 +572,11 @@ static int scsi_dev_info_list_add_str(char *dev_list) * matching flags value, else return the host or global default * settings. Called during scan time. **/ -int scsi_get_device_flags(struct scsi_device *sdev, - const unsigned char *vendor, - const unsigned char *model) +int scsi_get_device_flags(struct scsi_device *sdev, const unsigned char *vendor, + const unsigned char *model, unsigned int *flags) { return scsi_get_device_flags_keyed(sdev, vendor, model, - SCSI_DEVINFO_GLOBAL); + SCSI_DEVINFO_GLOBAL, flags); } @@ -586,6 +586,7 @@ int scsi_get_device_flags(struct scsi_device *sdev, * @vendor: vendor name * @model: model name * @key: list to look up + * @flags: (output) device specific flags * * Description: * Search the scsi_dev_info_list specified by @key for an entry @@ -596,28 +597,30 @@ int scsi_get_device_flags(struct scsi_device *sdev, int scsi_get_device_flags_keyed(struct scsi_device *sdev, const unsigned char *vendor, const unsigned char *model, - int key) + int key, unsigned int *flags) { struct scsi_dev_info_list *devinfo; int err; devinfo = scsi_dev_info_list_find(vendor, model, key); - if (!IS_ERR(devinfo)) - return devinfo->flags; + if (!IS_ERR(devinfo)) { + *flags = devinfo->flags; + return 0; + } err = PTR_ERR(devinfo); if (err != -ENOENT) return err; /* nothing found, return nothing */ - if (key != SCSI_DEVINFO_GLOBAL) + if (key != SCSI_DEVINFO_GLOBAL) { + *flags = 0; return 0; + } /* except for the global list, where we have an exception */ - if (sdev->sdev_bflags) - return sdev->sdev_bflags; - - return scsi_default_dev_flags; + *flags = sdev->sdev_bflags ? : scsi_default_dev_flags; + return 0; } EXPORT_SYMBOL(scsi_get_device_flags_keyed); diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 320318487bd4..d79759271fe3 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -52,10 +52,12 @@ enum { extern int scsi_get_device_flags(struct scsi_device *sdev, const unsigned char *vendor, - const unsigned char *model); + const unsigned char *model, + unsigned int *flags); extern int scsi_get_device_flags_keyed(struct scsi_device *sdev, const unsigned char *vendor, - const unsigned char *model, int key); + const unsigned char *model, int key, + unsigned int *flags); extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model, char *strflags, int flags, int key); diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index a0f2a20ea9e9..5b9571f30d82 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -650,8 +650,8 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result, * corresponding bit fields in scsi_device, so bflags * need not be passed as an argument. */ - *bflags = scsi_get_device_flags(sdev, &inq_result[8], - &inq_result[16]); + scsi_get_device_flags(sdev, &inq_result[8], &inq_result[16], + bflags); /* When the first pass succeeds we gain information about * what larger transfer lengths might work. */ @@ -1074,10 +1074,11 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, else scsi_device_put(sdev); - if (bflagsp) - *bflagsp = scsi_get_device_flags(sdev, - sdev->vendor, - sdev->model); + if (bflagsp) { + *bflagsp = 0; + scsi_get_device_flags(sdev, sdev->vendor, + sdev->model, bflagsp); + } return SCSI_SCAN_LUN_PRESENT; } scsi_device_put(sdev); diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index d0219e36080c..5f4cea2d07c8 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -221,9 +221,10 @@ static int spi_device_configure(struct transport_container *tc, { struct scsi_device *sdev = to_scsi_device(dev); struct scsi_target *starget = sdev->sdev_target; - unsigned bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8], - &sdev->inquiry[16], - SCSI_DEVINFO_SPI); + unsigned int bflags = 0; + + scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8], &sdev->inquiry[16], + SCSI_DEVINFO_SPI, &bflags); /* Populate the target capability fields with the values * gleaned from the device inquiry */