[PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize

Keoseong Park posted 1 patch 1 month, 1 week ago
drivers/ufs/core/ufs-sysfs.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
Posted by Keoseong Park 1 month, 1 week ago
JEDEC UFS spec defines 0xFFFFFFFF for dHIDAvailableSize as indicating no
valid fragmented size information. Returning the raw value can mislead
userspace. Return -ENODATA instead when the value is unavailable.

Signed-off-by: Keoseong Park <keosung.park@samsung.com>
---
 drivers/ufs/core/ufs-sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index b33f8656edb5..1017dd3ae5d3 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -1847,6 +1847,7 @@ static ssize_t defrag_trigger_store(struct device *dev,
 
 static DEVICE_ATTR_WO(defrag_trigger);
 
+#define UFS_HID_AVAILABLE_SIZE_INVALID 0xFFFFFFFFU
 static ssize_t fragmented_size_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
@@ -1859,6 +1860,9 @@ static ssize_t fragmented_size_show(struct device *dev,
 	if (ret)
 		return ret;
 
+	if (value == UFS_HID_AVAILABLE_SIZE_INVALID)
+		return -ENODATA;
+
 	return sysfs_emit(buf, "%u\n", value);
 }
 
-- 
2.25.1
Re: [PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
Posted by Martin K. Petersen 1 week, 6 days ago
On Fri, 26 Dec 2025 13:28:25 +0900, Keoseong Park wrote:

> JEDEC UFS spec defines 0xFFFFFFFF for dHIDAvailableSize as indicating no
> valid fragmented size information. Returning the raw value can mislead
> userspace. Return -ENODATA instead when the value is unavailable.
> 
> 

Applied to 6.20/scsi-queue, thanks!

[1/1] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
      https://git.kernel.org/mkp/scsi/c/695df7ea6099

-- 
Martin K. Petersen
Re: [PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
Posted by Martin K. Petersen 2 weeks, 6 days ago
Keoseong,

> JEDEC UFS spec defines 0xFFFFFFFF for dHIDAvailableSize as indicating no
> valid fragmented size information. Returning the raw value can mislead
> userspace. Return -ENODATA instead when the value is unavailable.

Applied to 6.20/scsi-staging, thanks!

-- 
Martin K. Petersen
Re: [PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
Posted by Bart Van Assche 3 weeks, 3 days ago
On 12/25/25 9:28 PM, Keoseong Park wrote:
> JEDEC UFS spec defines 0xFFFFFFFF for dHIDAvailableSize as indicating no
> valid fragmented size information. Returning the raw value can mislead
> userspace. Return -ENODATA instead when the value is unavailable.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Re: [PATCH] scsi: ufs: core: Handle sentinel value for dHIDAvailableSize
Posted by Peter Wang (王信友) 3 weeks, 3 days ago
On Fri, 2025-12-26 at 13:28 +0900, Keoseong Park wrote:
> JEDEC UFS spec defines 0xFFFFFFFF for dHIDAvailableSize as indicating
> no
> valid fragmented size information. Returning the raw value can
> mislead
> userspace. Return -ENODATA instead when the value is unavailable.
> 
> Signed-off-by: Keoseong Park <keosung.park@samsung.com>
> ---
>  drivers/ufs/core/ufs-sysfs.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-
> sysfs.c
> index b33f8656edb5..1017dd3ae5d3 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -1847,6 +1847,7 @@ static ssize_t defrag_trigger_store(struct
> device *dev,
> 
>  static DEVICE_ATTR_WO(defrag_trigger);
> 
> +#define UFS_HID_AVAILABLE_SIZE_INVALID 0xFFFFFFFFU
>  static ssize_t fragmented_size_show(struct device *dev,
>                 struct device_attribute *attr, char *buf)
>  {
> @@ -1859,6 +1860,9 @@ static ssize_t fragmented_size_show(struct
> device *dev,
>         if (ret)
>                 return ret;
> 
> +       if (value == UFS_HID_AVAILABLE_SIZE_INVALID)
> +               return -ENODATA;
> +
>         return sysfs_emit(buf, "%u\n", value);
>  }

Reviewed-by: Peter Wang <peter.wang@mediatek.com>