public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] firewire: Kill unnecessary buf check in device_attribute.show
@ 2024-01-22  5:39 Li Zhijian
  2024-01-22  5:39 ` [PATCH 2/2] firewire: Convert snprintf/sprintf to sysfs_emit Li Zhijian
  2024-01-22  8:56 ` [PATCH 1/2] firewire: Kill unnecessary buf check in device_attribute.show Takashi Sakamoto
  0 siblings, 2 replies; 7+ messages in thread
From: Li Zhijian @ 2024-01-22  5:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: Takashi Sakamoto, linux1394-devel, Li Zhijian

Per Documentation/filesystems/sysfs.rst:
> sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the
> method.

So we can kill the unnecessary buf check safely.

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 drivers/firewire/core-device.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 0547253d16fe..47d6cb3dc916 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -323,7 +323,7 @@ static ssize_t show_immediate(struct device *dev,
 	if (value < 0)
 		return -ENOENT;
 
-	return snprintf(buf, buf ? PAGE_SIZE : 0, "0x%06x\n", value);
+	return snprintf(buf, PAGE_SIZE, "0x%06x\n", value);
 }
 
 #define IMMEDIATE_ATTR(name, key)				\
@@ -335,8 +335,6 @@ static ssize_t show_text_leaf(struct device *dev,
 	struct config_rom_attribute *attr =
 		container_of(dattr, struct config_rom_attribute, attr);
 	const u32 *directories[] = {NULL, NULL};
-	size_t bufsize;
-	char dummy_buf[2];
 	int i, ret = -ENOENT;
 
 	down_read(&fw_device_rwsem);
@@ -358,15 +356,9 @@ static ssize_t show_text_leaf(struct device *dev,
 		}
 	}
 
-	if (buf) {
-		bufsize = PAGE_SIZE - 1;
-	} else {
-		buf = dummy_buf;
-		bufsize = 1;
-	}
-
 	for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) {
-		int result = fw_csr_string(directories[i], attr->key, buf, bufsize);
+		int result = fw_csr_string(directories[i], attr->key, buf,
+					   PAGE_SIZE - 1);
 		// Detected.
 		if (result >= 0)
 			ret = result;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-18  9:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22  5:39 [PATCH 1/2] firewire: Kill unnecessary buf check in device_attribute.show Li Zhijian
2024-01-22  5:39 ` [PATCH 2/2] firewire: Convert snprintf/sprintf to sysfs_emit Li Zhijian
2024-01-22  8:56 ` [PATCH 1/2] firewire: Kill unnecessary buf check in device_attribute.show Takashi Sakamoto
2024-03-18  4:46   ` Takashi Sakamoto
2024-03-18  6:24     ` Zhijian Li (Fujitsu)
2024-03-18  9:23       ` Takashi Sakamoto
2024-03-18  9:17     ` [PATCH] firewire: core: add memo about the caller of show functions for device attributes Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox