[PATCH v5] ufs: core: Add HID support
Huan Tang
tanghuan at vivo.com
Wed May 21 07:33:17 PDT 2025
>> +static const char * const hid_trigger_mode[] = {"disable",
>> "enable"};
>> +
>> +static ssize_t analysis_trigger_store(struct device *dev,
>> + struct device_attribute *attr, const char *buf,
>> size_t count)
>> +{
>> + struct ufs_hba *hba = dev_get_drvdata(dev);
>> + int mode;
>> + int ret;
>> +
>> + mode = sysfs_match_string(hid_trigger_mode, buf);
>> + if (mode < 0)
>> + return -EINVAL;
>>
>
> Hi Haun,
>
> Consider use below coding style for readability.
>
> if (sysfs_streq(buf, "enable"))
> mode = ...;
> else if (sysfs_streq(buf, "disable"))
> mode = ...;
> else
> return -EINVAL;
Hi peter sir,
Thank you for your comments and guidanceï¼
I think your modification will indeed improve the readability of the code.
What do you think of the following changes?
ufs-sysfs.c
+static ssize_t analysis_trigger_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ int mode;
+ int ret;
+
+ if (sysfs_streq(buf, "enable"))
+ mode = HID_ANALYSIS_ENABLE;
+ else if (sysfs_streq(buf, "disable"))
+ mode = HID_ANALYSIS_AND_DEFRAG_DISABLE;
+ else
+ return -EINVAL;
+
+ ret = hid_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+ QUERY_ATTR_IDN_HID_DEFRAG_OPERATION, &mode);
+
+ return ret < 0 ? ret : count;
+}
+
+static DEVICE_ATTR_WO(analysis_trigger);
+
+static ssize_t defrag_trigger_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ int mode;
+ int ret;
+
+ if (sysfs_streq(buf, "enable"))
+ mode = HID_ANALYSIS_AND_DEFRAG_ENABLE;
+ else if (sysfs_streq(buf, "disable"))
+ mode = HID_ANALYSIS_AND_DEFRAG_DISABLE;
+ else
+ return -EINVAL;
+
+ ret = hid_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
+ QUERY_ATTR_IDN_HID_DEFRAG_OPERATION, &mode);
+
+ return ret < 0 ? ret : count;
+}
Thanks
Huan
More information about the Linux-mediatek
mailing list