From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
support@areca.com.tw, linux-scsi@vger.kernel.org
Subject: [PATCH 10/10] scsi: arcmsr: Remove snprintf() from sysfs call-backs and replace with sysfs_emit()
Date: Thu, 8 Feb 2024 08:44:22 +0000 [thread overview]
Message-ID: <20240208084512.3803250-11-lee@kernel.org> (raw)
In-Reply-To: <20240208084512.3803250-1-lee@kernel.org>
Since snprintf() has the documented, but still rather strange trait of
returning the length of the data that *would have been* written to the
array if space were available, rather than the arguably more useful
length of data *actually* written, it is usually considered wise to use
something else instead in order to avoid confusion.
In the case of sysfs call-backs, new wrappers exist that do just that.
Link: https://lwn.net/Articles/69419/
Link: https://github.com/KSPP/linux/issues/105
Signed-off-by: Lee Jones <lee@kernel.org>
---
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: support@areca.com.tw
Cc: linux-scsi@vger.kernel.org
---
drivers/scsi/arcmsr/arcmsr_attr.c | 40 ++++++++-----------------------
1 file changed, 10 insertions(+), 30 deletions(-)
diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
index baeb5e7956902..c430c835503be 100644
--- a/drivers/scsi/arcmsr/arcmsr_attr.c
+++ b/drivers/scsi/arcmsr/arcmsr_attr.c
@@ -258,9 +258,7 @@ static ssize_t
arcmsr_attr_host_driver_version(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- ARCMSR_DRIVER_VERSION);
+ return sysfs_emit(buf, "%s\n", ARCMSR_DRIVER_VERSION);
}
static ssize_t
@@ -270,9 +268,7 @@ arcmsr_attr_host_driver_posted_cmd(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- atomic_read(&acb->ccboutstandingcount));
+ return sysfs_emit(buf, "%4d\n", atomic_read(&acb->ccboutstandingcount));
}
static ssize_t
@@ -282,9 +278,7 @@ arcmsr_attr_host_driver_reset(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->num_resets);
+ return sysfs_emit(buf, "%4d\n", acb->num_resets);
}
static ssize_t
@@ -294,9 +288,7 @@ arcmsr_attr_host_driver_abort(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->num_aborts);
+ return sysfs_emit(buf, "%4d\n", acb->num_aborts);
}
static ssize_t
@@ -306,9 +298,7 @@ arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- acb->firm_model);
+ return sysfs_emit(buf, "%s\n", acb->firm_model);
}
static ssize_t
@@ -319,9 +309,7 @@ arcmsr_attr_host_fw_version(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- acb->firm_version);
+ return sysfs_emit(buf, "%s\n", acb->firm_version);
}
static ssize_t
@@ -332,9 +320,7 @@ arcmsr_attr_host_fw_request_len(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_request_len);
+ return sysfs_emit(buf, "%4d\n", acb->firm_request_len);
}
static ssize_t
@@ -345,9 +331,7 @@ arcmsr_attr_host_fw_numbers_queue(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_numbers_queue);
+ return sysfs_emit(buf, "%4d\n", acb->firm_numbers_queue);
}
static ssize_t
@@ -358,9 +342,7 @@ arcmsr_attr_host_fw_sdram_size(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_sdram_size);
+ return sysfs_emit(buf, "%4d\n", acb->firm_sdram_size);
}
static ssize_t
@@ -371,9 +353,7 @@ arcmsr_attr_host_fw_hd_channels(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_hd_channels);
+ return sysfs_emit(buf, "%4d\n", acb->firm_hd_channels);
}
static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);
--
2.43.0.594.gd9cf4e227d-goog
next prev parent reply other threads:[~2024-02-08 8:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 8:44 [PATCH 00/10] scsi: Replace {v}snprintf() variants with safer alternatives Lee Jones
2024-02-08 8:44 ` [PATCH 01/10] scsi: 3w-xxxx: Trivial: Remove trailing whitespace Lee Jones
2024-02-10 6:58 ` Kees Cook
2024-02-08 8:44 ` [PATCH 02/10] scsi: 53c700: " Lee Jones
2024-02-10 6:58 ` Kees Cook
2024-02-08 8:44 ` [PATCH 03/10] scsi: NCR5380: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-08 10:22 ` Geert Uytterhoeven
2024-02-08 10:29 ` Lee Jones
2024-02-10 9:32 ` Finn Thain
2024-02-10 12:56 ` James Bottomley
2024-02-19 15:23 ` Lee Jones
2024-02-19 16:25 ` James Bottomley
2024-02-20 8:28 ` Lee Jones
2024-02-19 21:30 ` Kees Cook
2024-02-20 8:24 ` Lee Jones
2024-02-10 7:14 ` Kees Cook
2024-02-08 8:44 ` [PATCH 04/10] scsi: aacraid: linit: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Lee Jones
2024-02-10 7:00 ` Kees Cook
2024-02-08 8:44 ` [PATCH 05/10] scsi: aacraid: linit: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-10 7:03 ` Kees Cook
2024-02-08 8:44 ` [PATCH 06/10] scsi: aha1542: " Lee Jones
2024-02-10 7:06 ` Kees Cook
2024-02-08 8:44 ` [PATCH 07/10] scsi: aic7xxx: aicasm: Trivial: Remove trailing whitespace Lee Jones
2024-02-10 6:58 ` Kees Cook
2024-02-08 8:44 ` [PATCH 08/10] scsi: aic7xxx: aicasm: Replace snprintf() with the safer scnprintf() variant Lee Jones
2024-02-10 7:06 ` Kees Cook
2024-02-08 8:44 ` [PATCH 09/10] scsi: aic94xx: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Lee Jones
2024-02-10 7:13 ` Kees Cook
2024-02-08 8:44 ` Lee Jones [this message]
2024-02-10 7:13 ` [PATCH 10/10] scsi: arcmsr: " Kees Cook
2024-02-08 17:40 ` [PATCH 00/10] scsi: Replace {v}snprintf() variants with safer alternatives Bart Van Assche
2024-02-08 17:49 ` Lee Jones
2024-02-10 6:56 ` .mailmap support for removals (was Re: [PATCH 00/10] scsi: Replace {v}snprintf() variants with safer alternatives) Kees Cook
2024-02-10 22:56 ` Joe Perches
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=20240208084512.3803250-11-lee@kernel.org \
--to=lee@kernel.org \
--cc=jejb@linux.ibm.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=support@areca.com.tw \
/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