Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1134148pxu; Wed, 6 Jan 2021 13:17:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNoiqWL0QNdsFqwPEd/HO/f1RM4nXGGAaQi0FrJZcnO9ZSyVa8e7tsDlB+5zXhn9TDM0A7 X-Received: by 2002:a17:906:4985:: with SMTP id p5mr4155084eju.513.1609967870412; Wed, 06 Jan 2021 13:17:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609967870; cv=none; d=google.com; s=arc-20160816; b=0lo4B0xLVZW06QuzdIQ+QtqoV0ywiYaPVxEorHdx3TCw55VG+VMKkIWaFpcAErSLpg s96Y+WjaZV0b6oFxF53NKgAeMQBj9/etMRq10cqv3IBmHzJj4CgntzdbmIu2Nr+uPwJO SCGkZ2kU2arTfEoA090UMyvI98Xz34Vr+x83z15RZd1Fo91g/B8/o+VBv6AdSFJzfnIV sQtV6e/xlfPShe9zVtCB+VOsdkydYOvTb45di3FgTJ7xGEACNrM0sN6yz4cPOAwRZE8+ tSsz/7CeHGfvLqkgokEBCvtXq3uLEbcy18mZJ0jHLn5dpp5vUV63CpbFrGDJKhZ3o6aW hBYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=QRheIFhD7wkffZBzA+D0IWmMPq8XWePLdFJFeZNmTTE=; b=ebFu3ftoaAAvon+zAA3pkNrVpvthLJAylWihOw26226RLbwq83V8VcDDtK3u+U0bAx 6celzs7H85CC/7jPaf9pCJlZNWuHM3zhTDURhnw1KaUc9kPs97vk4Em/OY5Z+lHCG0Kk yLwkSIkRzPQVe9QXtrYp4edt5hobDKRHchDYdeiDcnnCV9CgmUDro84cW2EREzvOD7g+ qZmVQjfrD/TqMtk1+6eNzQ49MNbgeZWUwlmL++/z6OpCdR7EZa1t8jJ2BYPZt9kinFKE i9GYKwv4nDKps1hTNrVT5xPqUvuepOsP8JY7GYyDviTM5giV2wDtqYntgNQACHlsBkcT /LYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bRHWVrv+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p1si1376567ejw.42.2021.01.06.13.17.25; Wed, 06 Jan 2021 13:17:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bRHWVrv+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726086AbhAFVQd (ORCPT + 99 others); Wed, 6 Jan 2021 16:16:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbhAFVQd (ORCPT ); Wed, 6 Jan 2021 16:16:33 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7365C061575; Wed, 6 Jan 2021 13:15:52 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id b9so7050260ejy.0; Wed, 06 Jan 2021 13:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QRheIFhD7wkffZBzA+D0IWmMPq8XWePLdFJFeZNmTTE=; b=bRHWVrv+1LB6kz+uWchiHR1g44HJll0bbdUxQMPuSCRZEe21+dSyEzE2xavl84dkM/ 1JM0bR94HwZ7TdSFqkD7psrYb8Nr75S33ipPfDK10JpvVo9A/VrAh3FNYTzKFOmHe52z eDJx0KqcHFFKxq2CU20RZXqLvn4aEVAbtfI+vOVqDnuY1JyS1Fr5tmW/BVj1wM9dgOCs n+PdwuUEQGNJGBErw9DcjW4Z0E6p+657fM4CoIt0s2Hkm7OUeAidoC+AGViIi1BDPhHS rhzqNmrWTeGgT9j92KkxdDGIY8aVXYAc8SDGtPimo0edibIrhXoiBJ9iLJWX4ACzOuxS zt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QRheIFhD7wkffZBzA+D0IWmMPq8XWePLdFJFeZNmTTE=; b=dHMSYpcClc3rYIsGMPsXRy/YhZ3wM5M37SchcLnlClJgNLRb9hwTDv0s51iAtgJB5s 8rauMAxavwnilyTWmy5sj6XRQ7bCvYj9qwr/SKVbsi08hXTV5l2y4N78M4MspTTco+aK Y3kKQmEuwCaisocbMi0DV6/SFJLFF6FUDuVZvdyJUJSp1VMH1s+eDRLiLTSefeEYu4p+ +6F3AW/z0X8HlnchxR69rbslBihaDUn+RhYEDyJr4OjAG+0JUyxTJNrZncN4t2NoXrJA ER+4owvy566qux52kSnAa5O1iq13yE6Zq03xRe4WZgf2R2HKRnvW+x1fwWNdZpEJQMzz Thjw== X-Gm-Message-State: AOAM530220rG0TbuZ+Cv+nLZFSye2uFSiBu3cEJpAl42dA4uMI+eTrJA HADQ1UNxYL8Ij+Pme/A6ah4= X-Received: by 2002:a17:906:eb5b:: with SMTP id mc27mr4114502ejb.163.1609967751428; Wed, 06 Jan 2021 13:15:51 -0800 (PST) Received: from localhost.localdomain ([95.91.252.255]) by smtp.gmail.com with ESMTPSA id n8sm1708742eju.33.2021.01.06.13.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 13:15:50 -0800 (PST) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] scsi: ufs: Replace sprintf and snprintf with sysfs_emit Date: Wed, 6 Jan 2021 22:15:41 +0100 Message-Id: <20210106211541.23039-1-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bean Huo sprintf and snprintf may cause output defect in sysfs content, it is better to use new added sysfs_emit function which knows the size of the temporary buffer. Reviewed-by: Avri Altman Suggested-by: Greg Kroah-Hartman Signed-off-by: Bean Huo --- Nothing changed in this patch, just take it out from patchset: https://patchwork.kernel.org/project/linux-scsi/cover/20201224172010.10701-1-huobean@gmail.com/ --- drivers/scsi/ufs/ufs-sysfs.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 08e72b7eef6a..0e1438485133 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -67,7 +67,7 @@ static ssize_t rpm_lvl_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", hba->rpm_lvl); + return sysfs_emit(buf, "%d\n", hba->rpm_lvl); } static ssize_t rpm_lvl_store(struct device *dev, @@ -81,7 +81,7 @@ static ssize_t rpm_target_dev_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( ufs_pm_lvl_states[hba->rpm_lvl].dev_state)); } @@ -90,7 +90,7 @@ static ssize_t rpm_target_link_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( ufs_pm_lvl_states[hba->rpm_lvl].link_state)); } @@ -99,7 +99,7 @@ static ssize_t spm_lvl_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", hba->spm_lvl); + return sysfs_emit(buf, "%d\n", hba->spm_lvl); } static ssize_t spm_lvl_store(struct device *dev, @@ -113,7 +113,7 @@ static ssize_t spm_target_dev_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( ufs_pm_lvl_states[hba->spm_lvl].dev_state)); } @@ -122,7 +122,7 @@ static ssize_t spm_target_link_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( ufs_pm_lvl_states[hba->spm_lvl].link_state)); } @@ -165,7 +165,7 @@ static ssize_t auto_hibern8_show(struct device *dev, ufshcd_release(hba); pm_runtime_put_sync(hba->dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", ufshcd_ahit_to_us(ahit)); + return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); } static ssize_t auto_hibern8_store(struct device *dev, @@ -233,18 +233,18 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba, return -EINVAL; switch (param_size) { case 1: - ret = sprintf(sysfs_buf, "0x%02X\n", *desc_buf); + ret = sysfs_emit(sysfs_buf, "0x%02X\n", *desc_buf); break; case 2: - ret = sprintf(sysfs_buf, "0x%04X\n", + ret = sysfs_emit(sysfs_buf, "0x%04X\n", get_unaligned_be16(desc_buf)); break; case 4: - ret = sprintf(sysfs_buf, "0x%08X\n", + ret = sysfs_emit(sysfs_buf, "0x%08X\n", get_unaligned_be32(desc_buf)); break; case 8: - ret = sprintf(sysfs_buf, "0x%016llX\n", + ret = sysfs_emit(sysfs_buf, "0x%016llX\n", get_unaligned_be64(desc_buf)); break; } @@ -609,7 +609,7 @@ static ssize_t _name##_show(struct device *dev, \ SD_ASCII_STD); \ if (ret < 0) \ goto out; \ - ret = snprintf(buf, PAGE_SIZE, "%s\n", desc_buf); \ + ret = sysfs_emit(buf, "%s\n", desc_buf); \ out: \ pm_runtime_put_sync(hba->dev); \ kfree(desc_buf); \ @@ -659,7 +659,7 @@ static ssize_t _name##_show(struct device *dev, \ pm_runtime_put_sync(hba->dev); \ if (ret) \ return -EINVAL; \ - return sprintf(buf, "%s\n", flag ? "true" : "false"); \ + return sysfs_emit(buf, "%s\n", flag ? "true" : "false"); \ } \ static DEVICE_ATTR_RO(_name) @@ -717,7 +717,7 @@ static ssize_t _name##_show(struct device *dev, \ pm_runtime_put_sync(hba->dev); \ if (ret) \ return -EINVAL; \ - return sprintf(buf, "0x%08X\n", value); \ + return sysfs_emit(buf, "0x%08X\n", value); \ } \ static DEVICE_ATTR_RO(_name) @@ -856,7 +856,7 @@ static ssize_t dyn_cap_needed_attribute_show(struct device *dev, pm_runtime_put_sync(hba->dev); if (ret) return -EINVAL; - return sprintf(buf, "0x%08X\n", value); + return sysfs_emit(buf, "0x%08X\n", value); } static DEVICE_ATTR_RO(dyn_cap_needed_attribute); -- 2.17.1