[PATCH v2] drivers: firmware: stratix10-rsu: Fix max_retry counter value
From: kah . jing . lee
Date: Thu Aug 17 2023 - 22:25:48 EST
From: Kah Jing Lee <kah.jing.lee@xxxxxxxxx>
Fix the max_retry value because the value is truncated at scnprintf format
specifier, with added hex symbol and newline.
Update scnprintf and sprintf with sysfs_emit to ensure no overflow.
Signed-off-by: Kah Jing Lee <kah.jing.lee@xxxxxxxxx>
---
v2:
- Update scnprintf and sprintf with sysfs_emit to ensure no overflow.
---
drivers/firmware/stratix10-rsu.c | 33 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/firmware/stratix10-rsu.c b/drivers/firmware/stratix10-rsu.c
index e51c95f8d445..c3e3d6b092a2 100644
--- a/drivers/firmware/stratix10-rsu.c
+++ b/drivers/firmware/stratix10-rsu.c
@@ -328,7 +328,7 @@ static ssize_t current_image_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08lx\n", priv->status.current_image);
+ return sysfs_emit(buf, "0x%08lx\n", priv->status.current_image);
}
static ssize_t fail_image_show(struct device *dev,
@@ -339,7 +339,7 @@ static ssize_t fail_image_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08lx\n", priv->status.fail_image);
+ return sysfs_emit(buf, "0x%08lx\n", priv->status.fail_image);
}
static ssize_t version_show(struct device *dev, struct device_attribute *attr,
@@ -350,7 +350,7 @@ static ssize_t version_show(struct device *dev, struct device_attribute *attr,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->status.version);
+ return sysfs_emit(buf, "0x%08x\n", priv->status.version);
}
static ssize_t state_show(struct device *dev, struct device_attribute *attr,
@@ -361,7 +361,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->status.state);
+ return sysfs_emit(buf, "0x%08x\n", priv->status.state);
}
static ssize_t error_location_show(struct device *dev,
@@ -372,7 +372,7 @@ static ssize_t error_location_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->status.error_location);
+ return sysfs_emit(buf, "0x%08x\n", priv->status.error_location);
}
static ssize_t error_details_show(struct device *dev,
@@ -383,7 +383,7 @@ static ssize_t error_details_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->status.error_details);
+ return sysfs_emit(buf, "0x%08x\n", priv->status.error_details);
}
static ssize_t retry_counter_show(struct device *dev,
@@ -394,7 +394,7 @@ static ssize_t retry_counter_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->retry_counter);
+ return sysfs_emit(buf, "0x%08x\n", priv->retry_counter);
}
static ssize_t max_retry_show(struct device *dev,
@@ -405,8 +405,7 @@ static ssize_t max_retry_show(struct device *dev,
if (!priv)
return -ENODEV;
- return scnprintf(buf, sizeof(priv->max_retry),
- "0x%08x\n", priv->max_retry);
+ return sysfs_emit(buf, PAGE_SIZE, "0x%08x\n", priv->max_retry);
}
static ssize_t dcmf0_show(struct device *dev,
@@ -417,7 +416,7 @@ static ssize_t dcmf0_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf0);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_version.dcmf0);
}
static ssize_t dcmf1_show(struct device *dev,
@@ -428,7 +427,7 @@ static ssize_t dcmf1_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf1);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_version.dcmf1);
}
static ssize_t dcmf2_show(struct device *dev,
@@ -439,7 +438,7 @@ static ssize_t dcmf2_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf2);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_version.dcmf2);
}
static ssize_t dcmf3_show(struct device *dev,
@@ -450,7 +449,7 @@ static ssize_t dcmf3_show(struct device *dev,
if (!priv)
return -ENODEV;
- return sprintf(buf, "0x%08x\n", priv->dcmf_version.dcmf3);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_version.dcmf3);
}
static ssize_t dcmf0_status_show(struct device *dev,
@@ -464,7 +463,7 @@ static ssize_t dcmf0_status_show(struct device *dev,
if (priv->dcmf_status.dcmf0 == INVALID_DCMF_STATUS)
return -EIO;
- return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf0);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_status.dcmf0);
}
static ssize_t dcmf1_status_show(struct device *dev,
@@ -478,7 +477,7 @@ static ssize_t dcmf1_status_show(struct device *dev,
if (priv->dcmf_status.dcmf1 == INVALID_DCMF_STATUS)
return -EIO;
- return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf1);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_status.dcmf1);
}
static ssize_t dcmf2_status_show(struct device *dev,
@@ -492,7 +491,7 @@ static ssize_t dcmf2_status_show(struct device *dev,
if (priv->dcmf_status.dcmf2 == INVALID_DCMF_STATUS)
return -EIO;
- return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf2);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_status.dcmf2);
}
static ssize_t dcmf3_status_show(struct device *dev,
@@ -506,7 +505,7 @@ static ssize_t dcmf3_status_show(struct device *dev,
if (priv->dcmf_status.dcmf3 == INVALID_DCMF_STATUS)
return -EIO;
- return sprintf(buf, "0x%08x\n", priv->dcmf_status.dcmf3);
+ return sysfs_emit(buf, "0x%08x\n", priv->dcmf_status.dcmf3);
}
static ssize_t reboot_image_store(struct device *dev,
struct device_attribute *attr,
base-commit: c1a515d3c0270628df8ae5f5118ba859b85464a2
--
2.25.1