From patchwork Fri Dec 23 19:45:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 636831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0326C4332F for ; Fri, 23 Dec 2022 19:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232915AbiLWTqE (ORCPT ); Fri, 23 Dec 2022 14:46:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232814AbiLWTqB (ORCPT ); Fri, 23 Dec 2022 14:46:01 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01D23630A; Fri, 23 Dec 2022 11:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1671824742; bh=blHvl4TwFi6Skuv7VrvkLrtt2LPWZsPhT59Ln7QToC0=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=BWqqKwNT+21sNLvupwmjKXe/uMjPS7JDfTbdIDkU26N4ANxF4mQoQnGmpQtrERXoz RxwaUWl8Oi1wavFWAFmwp9pN2JohJbtF7PN0+9WNKANZmyINUwj1Zo4LQPOZ6PPP2f AgsavzcvRZmhIOf5tt5HPZyR7jAOgV0QueJlSfOs= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Fri, 23 Dec 2022 20:45:42 +0100 (CET) X-EA-Auth: Jkjzspo6MwUxQr8f8PpkqhxDaeHVHWwM9XEEMi6XVUeXbBe9SOg1BaM5HVpi4EeR6T6Fgem9bs0G5dYVjj78dqCrvScd/0rz Date: Sat, 24 Dec 2022 01:15:35 +0530 From: Deepak R Varma To: Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] scsi: myrb: Use sysfs_emit in show function callsbacks Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org According to Documentation/filesystems/sysfs.rst, the show() callback function of kobject attributes should strictly use sysfs_emit instead of sprintf family functions. Also, merge split lines wherever possible due to shortened length of lines. Issue identified using the coccinelle device_attr_show.cocci script. Signed-off-by: Deepak R Varma --- drivers/scsi/myrb.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.34.1 diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c index e885c1dbf61f..ab7eab0dfa38 100644 --- a/drivers/scsi/myrb.c +++ b/drivers/scsi/myrb.c @@ -1767,7 +1767,7 @@ static ssize_t raid_state_show(struct device *dev, int ret; if (!sdev->hostdata) - return snprintf(buf, 16, "Unknown\n"); + return sysfs_emit(buf, "Unknown\n"); if (sdev->channel == myrb_logical_channel(sdev->host)) { struct myrb_ldev_info *ldev_info = sdev->hostdata; @@ -1886,11 +1886,10 @@ static ssize_t raid_level_show(struct device *dev, name = myrb_raidlevel_name(ldev_info->raid_level); if (!name) - return snprintf(buf, 32, "Invalid (%02X)\n", - ldev_info->state); - return snprintf(buf, 32, "%s\n", name); + return sysfs_emit(buf, "Invalid (%02X)\n", ldev_info->state); + return sysfs_emit(buf, "%s\n", name); } - return snprintf(buf, 32, "Physical Drive\n"); + return sysfs_emit(buf, "Physical Drive\n"); } static DEVICE_ATTR_RO(raid_level); @@ -1903,17 +1902,17 @@ static ssize_t rebuild_show(struct device *dev, unsigned char status; if (sdev->channel < myrb_logical_channel(sdev->host)) - return snprintf(buf, 32, "physical device - not rebuilding\n"); + return sysfs_emit(buf, "physical device - not rebuilding\n"); status = myrb_get_rbld_progress(cb, &rbld_buf); if (rbld_buf.ldev_num != sdev->id || status != MYRB_STATUS_SUCCESS) - return snprintf(buf, 32, "not rebuilding\n"); + return sysfs_emit(buf, "not rebuilding\n"); - return snprintf(buf, 32, "rebuilding block %u of %u\n", - rbld_buf.ldev_size - rbld_buf.blocks_left, - rbld_buf.ldev_size); + return sysfs_emit(buf, "rebuilding block %u of %u\n", + rbld_buf.ldev_size - rbld_buf.blocks_left, + rbld_buf.ldev_size); } static ssize_t rebuild_store(struct device *dev, @@ -2140,7 +2139,7 @@ static ssize_t ctlr_num_show(struct device *dev, struct Scsi_Host *shost = class_to_shost(dev); struct myrb_hba *cb = shost_priv(shost); - return snprintf(buf, 20, "%u\n", cb->ctlr_num); + return sysfs_emit(buf, "%u\n", cb->ctlr_num); } static DEVICE_ATTR_RO(ctlr_num); @@ -2150,7 +2149,7 @@ static ssize_t firmware_show(struct device *dev, struct Scsi_Host *shost = class_to_shost(dev); struct myrb_hba *cb = shost_priv(shost); - return snprintf(buf, 16, "%s\n", cb->fw_version); + return sysfs_emit(buf, "%s\n", cb->fw_version); } static DEVICE_ATTR_RO(firmware); @@ -2160,7 +2159,7 @@ static ssize_t model_show(struct device *dev, struct Scsi_Host *shost = class_to_shost(dev); struct myrb_hba *cb = shost_priv(shost); - return snprintf(buf, 16, "%s\n", cb->model_name); + return sysfs_emit(buf, "%s\n", cb->model_name); } static DEVICE_ATTR_RO(model);