From patchwork Thu Feb 28 03:57:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 10832521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DB531805 for ; Thu, 28 Feb 2019 03:58:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4008C2E231 for ; Thu, 28 Feb 2019 03:58:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3366D2E41A; Thu, 28 Feb 2019 03:58:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 48C662E28C for ; Thu, 28 Feb 2019 03:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730509AbfB1D6I (ORCPT ); Wed, 27 Feb 2019 22:58:08 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49086 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730410AbfB1D6I (ORCPT ); Wed, 27 Feb 2019 22:58:08 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1S3moUf178406 for ; Thu, 28 Feb 2019 03:58:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=Dka2BBagV2cxQ+J1o/k1LVG6/lpR/lSFPM4dFpVkics=; b=NpCM7AyykeF5Ll4eFckfyOi6lZqU0ivXMvlcQVmWOCnl7h8JlovUKVGzpOM7xTaca8yX NLFCCdSkZVEzq3a74AYZgFdoOm5Of6Lw/C9wf0Esl4qocbIUGduSsLOZsToFb0EIpBzj 4qBI+WYSj/kxZ/r68p7E3KGYuhXaUamKteR6VUXjVixsLKCa+dr9kPbOiayYYM/nbI4d xyK9DPTyuR01Q67zm7ytwLYhpq//s6ecBEDnWlVzXNlARXSwqja1SXGKCt3RWvRvSorX ColrU23Ydg5uHALX32QUlbKCQqVkCCCD0+uBwtHBYgRG4XjOcP36+6Yp+soyiMHZsTnN JQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2qtupeesux-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Feb 2019 03:58:06 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1S3w6lL010876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Feb 2019 03:58:06 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1S3w5vY023859 for ; Thu, 28 Feb 2019 03:58:06 GMT Received: from ca-mkp.ca.oracle.com (/10.156.108.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 27 Feb 2019 19:57:44 -0800 From: "Martin K. Petersen" To: linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" Subject: [PATCH 1/2] scsi: sd: Use revalidate buffer for VPD pages Date: Wed, 27 Feb 2019 22:57:32 -0500 Message-Id: <20190228035733.19793-2-martin.petersen@oracle.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190228035733.19793-1-martin.petersen@oracle.com> References: <9f00159eacd346bbbc2aeb1708f6831f@mail.gmail.com> <20190228035733.19793-1-martin.petersen@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9180 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902280024 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 No point in allocating separate memory for the VPD pages we're querying. Use the buffer we already allocated. Signed-off-by: Martin K. Petersen --- drivers/scsi/scsi.c | 1 + drivers/scsi/sd.c | 48 ++++++++++++++------------------------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 7675ff0ca2ea..1d58e466722f 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -341,6 +341,7 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer, cmd[3] = len >> 8; cmd[4] = len & 0xff; cmd[5] = 0; /* Control byte */ + memset(buffer, 0x0, len); /* * I'm not convinced we need to try quite this hard to get VPD, but diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index cc175b78b366..df9538e57dcb 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2879,16 +2879,14 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer) * sd_read_block_limits - Query disk device for preferred I/O sizes. * @sdkp: disk to query */ -static void sd_read_block_limits(struct scsi_disk *sdkp) +static void sd_read_block_limits(struct scsi_disk *sdkp, unsigned char *buffer) { unsigned int sector_sz = sdkp->device->sector_size; const int vpd_len = 64; - unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL); - if (!buffer || - /* Block Limits VPD */ - scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len)) - goto out; + /* Block Limits VPD */ + if (scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len)) + return; blk_queue_io_min(sdkp->disk->queue, get_unaligned_be16(&buffer[6]) * sector_sz); @@ -2902,7 +2900,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) sdkp->max_ws_blocks = (u32)get_unaligned_be64(&buffer[36]); if (!sdkp->lbpme) - goto out; + return; lba_count = get_unaligned_be32(&buffer[20]); desc_count = get_unaligned_be32(&buffer[24]); @@ -2934,28 +2932,21 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) sd_config_discard(sdkp, SD_LBP_DISABLE); } } - - out: - kfree(buffer); } /** * sd_read_block_characteristics - Query block dev. characteristics * @sdkp: disk to query */ -static void sd_read_block_characteristics(struct scsi_disk *sdkp) +static void sd_read_block_characteristics(struct scsi_disk *sdkp, unsigned char *buffer) { struct request_queue *q = sdkp->disk->queue; - unsigned char *buffer; u16 rot; const int vpd_len = 64; - buffer = kmalloc(vpd_len, GFP_KERNEL); - - if (!buffer || - /* Block Device Characteristics VPD */ - scsi_get_vpd_page(sdkp->device, 0xb1, buffer, vpd_len)) - goto out; + /* Block Device Characteristics VPD */ + if (scsi_get_vpd_page(sdkp->device, 0xb1, buffer, vpd_len)) + return; rot = get_unaligned_be16(&buffer[4]); @@ -2985,35 +2976,26 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) if (blk_queue_is_zoned(q) && sdkp->first_scan) sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n", q->limits.zoned == BLK_ZONED_HM ? "managed" : "aware"); - - out: - kfree(buffer); } /** * sd_read_block_provisioning - Query provisioning VPD page * @sdkp: disk to query */ -static void sd_read_block_provisioning(struct scsi_disk *sdkp) +static void sd_read_block_provisioning(struct scsi_disk *sdkp, unsigned char *buffer) { - unsigned char *buffer; const int vpd_len = 8; if (sdkp->lbpme == 0) return; - buffer = kmalloc(vpd_len, GFP_KERNEL); - - if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len)) - goto out; + if (scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len)) + return; sdkp->lbpvpd = 1; sdkp->lbpu = (buffer[5] >> 7) & 1; /* UNMAP */ sdkp->lbpws = (buffer[5] >> 6) & 1; /* WRITE SAME(16) with UNMAP */ sdkp->lbpws10 = (buffer[5] >> 5) & 1; /* WRITE SAME(10) with UNMAP */ - - out: - kfree(buffer); } static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) @@ -3102,9 +3084,9 @@ static int sd_revalidate_disk(struct gendisk *disk) sd_read_capacity(sdkp, buffer); if (scsi_device_supports_vpd(sdp)) { - sd_read_block_provisioning(sdkp); - sd_read_block_limits(sdkp); - sd_read_block_characteristics(sdkp); + sd_read_block_provisioning(sdkp, buffer); + sd_read_block_limits(sdkp, buffer); + sd_read_block_characteristics(sdkp, buffer); sd_zbc_read_zones(sdkp, buffer); }