From patchwork Mon May 15 19:13:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ewan Milne X-Patchwork-Id: 9727781 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 EB52A6028A for ; Mon, 15 May 2017 19:13:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD288289B1 for ; Mon, 15 May 2017 19:13:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1A69289C3; Mon, 15 May 2017 19:13:29 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 80E45289B1 for ; Mon, 15 May 2017 19:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965240AbdEOTN2 (ORCPT ); Mon, 15 May 2017 15:13:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44814 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964967AbdEOTN2 (ORCPT ); Mon, 15 May 2017 15:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D07E63680B for ; Mon, 15 May 2017 19:13:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D07E63680B Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=emilne@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D07E63680B Received: from emilne.csb (unknown [10.18.25.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E69A5DD6D for ; Mon, 15 May 2017 19:13:27 +0000 (UTC) From: "Ewan D. Milne" To: linux-scsi@vger.kernel.org Subject: [PATCH] sd: fix sysfs writes to "provisioning_mode" and "zeroing_mode" Date: Mon, 15 May 2017 15:13:26 -0400 Message-Id: <1494875606-6298-1-git-send-email-emilne@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 15 May 2017 19:13:28 +0000 (UTC) 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 From: "Ewan D. Milne" Change to use strlen() of the desired string for the length parameter to strncmp(). Otherwise one cannot simply use a command like 'echo "writesame_16" > .../provisioning_mode'. This patch makes sysfs writes consistent with other usage. Signed-off-by: Ewan D. Milne --- drivers/scsi/sd.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index f9d1432..a5eacea 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -402,15 +402,20 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr, if (sdp->type != TYPE_DISK) return -EINVAL; - if (!strncmp(buf, lbp_mode[SD_LBP_UNMAP], 20)) + if (!strncmp(buf, lbp_mode[SD_LBP_UNMAP], + strlen(lbp_mode[SD_LBP_UNMAP]))) sd_config_discard(sdkp, SD_LBP_UNMAP); - else if (!strncmp(buf, lbp_mode[SD_LBP_WS16], 20)) + else if (!strncmp(buf, lbp_mode[SD_LBP_WS16], + strlen(lbp_mode[SD_LBP_WS16]))) sd_config_discard(sdkp, SD_LBP_WS16); - else if (!strncmp(buf, lbp_mode[SD_LBP_WS10], 20)) + else if (!strncmp(buf, lbp_mode[SD_LBP_WS10], + strlen(lbp_mode[SD_LBP_WS10]))) sd_config_discard(sdkp, SD_LBP_WS10); - else if (!strncmp(buf, lbp_mode[SD_LBP_ZERO], 20)) + else if (!strncmp(buf, lbp_mode[SD_LBP_ZERO], + strlen(lbp_mode[SD_LBP_ZERO]))) sd_config_discard(sdkp, SD_LBP_ZERO); - else if (!strncmp(buf, lbp_mode[SD_LBP_DISABLE], 20)) + else if (!strncmp(buf, lbp_mode[SD_LBP_DISABLE], + strlen(lbp_mode[SD_LBP_DISABLE]))) sd_config_discard(sdkp, SD_LBP_DISABLE); else return -EINVAL; @@ -444,13 +449,17 @@ zeroing_mode_store(struct device *dev, struct device_attribute *attr, if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if (!strncmp(buf, zeroing_mode[SD_ZERO_WRITE], 20)) + if (!strncmp(buf, zeroing_mode[SD_ZERO_WRITE], + strlen(zeroing_mode[SD_ZERO_WRITE]))) sdkp->zeroing_mode = SD_ZERO_WRITE; - else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS], 20)) + else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS], + strlen(zeroing_mode[SD_ZERO_WS]))) sdkp->zeroing_mode = SD_ZERO_WS; - else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS16_UNMAP], 20)) + else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS16_UNMAP], + strlen(zeroing_mode[SD_ZERO_WS16_UNMAP]))) sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP; - else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS10_UNMAP], 20)) + else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS10_UNMAP], + strlen(zeroing_mode[SD_ZERO_WS10_UNMAP]))) sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP; else return -EINVAL;