Re: [PATCH v2 1/2] scsi: ufs: Probe for temperature notification support

From: Bart Van Assche
Date: Thu Sep 09 2021 - 12:27:08 EST


On 9/8/21 11:34 PM, Avri Altman wrote:
+static bool ufs_temp_enabled(struct ufs_hba *hba, struct ufs_hwmon_data *data)
+{
+ u32 ee_mask;
+
+ if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ QUERY_ATTR_IDN_EE_CONTROL, 0, 0, &ee_mask))
+ return false;
+
+ return (data->mask & ee_mask & MASK_EE_TOO_HIGH_TEMP) ||
+ (data->mask & ee_mask & MASK_EE_TOO_LOW_TEMP);
+}

The above function uses data->mask but not data so it's probably better to pass
data->mask directly as the second argument.

+static bool ufs_temp_valid(struct ufs_hba *hba, struct ufs_hwmon_data *data,
+ enum attr_idn idn, u32 value)
+{
+ return (idn == QUERY_ATTR_IDN_CASE_ROUGH_TEMP && value >= 1 &&
+ value <= 250 && ufs_temp_enabled(hba, data)) ||
+ (idn == QUERY_ATTR_IDN_HIGH_TEMP_BOUND && value >= 100 &&
+ value <= 250) ||
+ (idn == QUERY_ATTR_IDN_LOW_TEMP_BOUND && value >= 1 &&
+ value <= 80);
+}

Same comment for this function - if the above comment is addressed 'mask' can be
passed as an argument instead of 'data'.

+static int ufs_get_temp(struct ufs_hba *hba, struct ufs_hwmon_data *data,
+ enum attr_idn idn)
+{
+ u32 value;
+
+ if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, idn, 0, 0,
+ &value))
+ return 0;
+
+ if (ufs_temp_valid(hba, data, idn, value))
+ return value - 80;
+
+ return 0;
+}

Same comment here.

+void ufs_hwmon_remove(struct ufs_hba *hba)
+{
+ if (hba->hwmon_device) {
+ struct ufs_hwmon_data *data =
+ dev_get_drvdata(hba->hwmon_device);
+
+ hwmon_device_unregister(hba->hwmon_device);
+ hba->hwmon_device = NULL;
+ kfree(data);
+ }
+}

Please use the "early return" style since that is the most widely used style
in the Linux kernel (if (!hba->hwmon_device) return).

Thanks,

Bart.