From: Deepak R Varma <drv@mailo.com>
To: outreachy@lists.linux.dev,
Sven Van Asbroeck <TheSven73@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v3] staging: fieldbus: use sysfs_emit() in show functions
Date: Wed, 9 Nov 2022 16:12:43 +0530 [thread overview]
Message-ID: <Y2uEIzebbM/Fs5Jz@qemulion> (raw)
The show() methods should only use sysfs_emit() when formatting values
to be returned to the user space.
Ref: Documentation/filesystems/sysfs.rst
Issue identified by coccicheck.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Changes in v3:
1. Include other show functions from the same file in the scope of this
patch. Feedback from gregkh@linuxfoundation.org
2. Simplify code comment.
Changes in v2:
1. Switch to using sysfs_emit instead of scnprintf
2. Update patch subject and log accordingly
Feedback from gregkh@linuxfoundation.org
drivers/staging/fieldbus/dev_core.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/fieldbus/dev_core.c b/drivers/staging/fieldbus/dev_core.c
index 5aab734606ea..5f54f2674bd1 100644
--- a/drivers/staging/fieldbus/dev_core.c
+++ b/drivers/staging/fieldbus/dev_core.c
@@ -28,7 +28,7 @@ static ssize_t online_show(struct device *dev, struct device_attribute *attr,
{
struct fieldbus_dev *fb = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", !!fb->online);
+ return sysfs_emit(buf, "%d\n", !!fb->online);
}
static DEVICE_ATTR_RO(online);
@@ -39,7 +39,7 @@ static ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
if (!fb->enable_get)
return -EINVAL;
- return sprintf(buf, "%d\n", !!fb->enable_get(fb));
+ return sysfs_emit(buf, "%d\n", !!fb->enable_get(fb));
}
static ssize_t enabled_store(struct device *dev, struct device_attribute *attr,
@@ -66,11 +66,8 @@ static ssize_t card_name_show(struct device *dev, struct device_attribute *attr,
{
struct fieldbus_dev *fb = dev_get_drvdata(dev);
- /*
- * card_name was provided by child driver, could potentially be long.
- * protect against buffer overrun.
- */
- return snprintf(buf, PAGE_SIZE, "%s\n", fb->card_name);
+ /* card_name was provided by child driver. */
+ return sysfs_emit(buf, "%s\n", fb->card_name);
}
static DEVICE_ATTR_RO(card_name);
@@ -79,7 +76,7 @@ static ssize_t read_area_size_show(struct device *dev,
{
struct fieldbus_dev *fb = dev_get_drvdata(dev);
- return sprintf(buf, "%zu\n", fb->read_area_sz);
+ return sysfs_emit(buf, "%zu\n", fb->read_area_sz);
}
static DEVICE_ATTR_RO(read_area_size);
@@ -88,7 +85,7 @@ static ssize_t write_area_size_show(struct device *dev,
{
struct fieldbus_dev *fb = dev_get_drvdata(dev);
- return sprintf(buf, "%zu\n", fb->write_area_sz);
+ return sysfs_emit(buf, "%zu\n", fb->write_area_sz);
}
static DEVICE_ATTR_RO(write_area_size);
@@ -116,7 +113,7 @@ static ssize_t fieldbus_type_show(struct device *dev,
break;
}
- return sprintf(buf, "%s\n", t);
+ return sysfs_emit(buf, "%s\n", t);
}
static DEVICE_ATTR_RO(fieldbus_type);
--
2.34.1
reply other threads:[~2022-11-09 10:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2uEIzebbM/Fs5Jz@qemulion \
--to=drv@mailo.com \
--cc=TheSven73@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox