From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
Adaptec OEM Raid Solutions <aacraid@microsemi.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"PMC-Sierra, Inc" <aacraid@pmc-sierra.com>,
linux-scsi@vger.kernel.org
Subject: [PATCH 04/10] scsi: aacraid: linit: Remove snprintf() from sysfs call-backs and replace with sysfs_emit()
Date: Thu, 8 Feb 2024 08:44:16 +0000 [thread overview]
Message-ID: <20240208084512.3803250-5-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: Adaptec OEM Raid Solutions <aacraid@microsemi.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "PMC-Sierra, Inc" <aacraid@pmc-sierra.com>
Cc: linux-scsi@vger.kernel.org
---
drivers/scsi/aacraid/linit.c | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 68f4dbcfff492..69526e2bd2e78 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -558,11 +558,9 @@ static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *
struct scsi_device *sdev = to_scsi_device(dev);
struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
if (sdev_channel(sdev) != CONTAINER_CHANNEL)
- return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach
- ? "Hidden\n" :
+ return sysfs_emit(buf, sdev->no_uld_attach ? "Hidden\n" :
((aac->jbod && (sdev->type == TYPE_DISK)) ? "JBOD\n" : ""));
- return snprintf(buf, PAGE_SIZE, "%s\n",
- get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
+ return sysfs_emit(buf, "%s\n", get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
}
static struct device_attribute aac_raid_level_attr = {
@@ -1195,10 +1193,9 @@ static ssize_t aac_show_model(struct device *device,
++cp;
while (*cp == ' ')
++cp;
- len = snprintf(buf, PAGE_SIZE, "%s\n", cp);
+ len = sysfs_emit(buf, "%s\n", cp);
} else
- len = snprintf(buf, PAGE_SIZE, "%s\n",
- aac_drivers[dev->cardtype].model);
+ len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].model);
return len;
}
@@ -1214,12 +1211,11 @@ static ssize_t aac_show_vendor(struct device *device,
char *cp = sup_adap_info->adapter_type_text;
while (*cp && *cp != ' ')
++cp;
- len = snprintf(buf, PAGE_SIZE, "%.*s\n",
+ len = sysfs_emit(buf, "%.*s\n",
(int)(cp - (char *)sup_adap_info->adapter_type_text),
sup_adap_info->adapter_type_text);
} else
- len = snprintf(buf, PAGE_SIZE, "%s\n",
- aac_drivers[dev->cardtype].vname);
+ len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].vname);
return len;
}
@@ -1230,7 +1226,7 @@ static ssize_t aac_show_flags(struct device *cdev,
struct aac_dev *dev = (struct aac_dev*)class_to_shost(cdev)->hostdata;
if (nblank(dprintk(x)))
- len = snprintf(buf, PAGE_SIZE, "dprintk\n");
+ len = sysfs_emit(buf, "dprintk\n");
#ifdef AAC_DETAILED_STATUS_INFO
len += scnprintf(buf + len, PAGE_SIZE - len,
"AAC_DETAILED_STATUS_INFO\n");
@@ -1258,7 +1254,7 @@ static ssize_t aac_show_kernel_version(struct device *device,
int len, tmp;
tmp = le32_to_cpu(dev->adapter_info.kernelrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
le32_to_cpu(dev->adapter_info.kernelbuild));
return len;
@@ -1272,7 +1268,7 @@ static ssize_t aac_show_monitor_version(struct device *device,
int len, tmp;
tmp = le32_to_cpu(dev->adapter_info.monitorrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
le32_to_cpu(dev->adapter_info.monitorbuild));
return len;
@@ -1286,7 +1282,7 @@ static ssize_t aac_show_bios_version(struct device *device,
int len, tmp;
tmp = le32_to_cpu(dev->adapter_info.biosrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
le32_to_cpu(dev->adapter_info.biosbuild));
return len;
@@ -1296,7 +1292,7 @@ static ssize_t aac_show_driver_version(struct device *device,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version);
+ return sysfs_emit(buf, "%s\n", aac_driver_version);
}
static ssize_t aac_show_serial_number(struct device *device,
@@ -1322,15 +1318,13 @@ static ssize_t aac_show_serial_number(struct device *device,
static ssize_t aac_show_max_channel(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_channel);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_channel);
}
static ssize_t aac_show_max_id(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_id);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_id);
}
static ssize_t aac_store_reset_adapter(struct device *device,
@@ -1360,7 +1354,7 @@ static ssize_t aac_show_reset_adapter(struct device *device,
tmp = aac_adapter_check_health(dev);
if ((tmp == 0) && dev->in_reset)
tmp = -EBUSY;
- len = snprintf(buf, PAGE_SIZE, "0x%x\n", tmp);
+ len = sysfs_emit(buf, "0x%x\n", tmp);
return len;
}
--
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 ` Lee Jones [this message]
2024-02-10 7:00 ` [PATCH 04/10] scsi: aacraid: linit: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() 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 ` [PATCH 10/10] scsi: arcmsr: " Lee Jones
2024-02-10 7:13 ` 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-5-lee@kernel.org \
--to=lee@kernel.org \
--cc=aacraid@microsemi.com \
--cc=aacraid@pmc-sierra.com \
--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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.