On Thu, 2018-02-01 at 18:15 +0200, Stanislav Nijnikov wrote:
> +ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
> +                               enum desc_idn desc_id,
> +                               u8 desc_index,
> +                               u8 param_offset,
> +                               u8 *sysfs_buf,
> +                               u8 param_size)
> +{
> +     u8 desc_buf[UFS_PARAM_QWORD_SIZE] = {0};
> +     int ret;
> +
> +     if (param_size > UFS_PARAM_QWORD_SIZE)
> +             return -EINVAL;
> +
> +     ret = ufshcd_read_desc_param(hba, desc_id, desc_index,
> +                             param_offset, desc_buf, param_size);
> +     if (ret)
> +             return -EINVAL;
> +     switch (param_size) {
> +     case UFS_PARAM_BYTE_SIZE:
> +             ret = sprintf(sysfs_buf, "0x%02X\n", *desc_buf);
> +             break;
> +     case UFS_PARAM_WORD_SIZE:
> +             ret = sprintf(sysfs_buf, "0x%04X\n",
> +                     be16_to_cpu(*((u16 *)desc_buf)));
> +             break;
> +     case UFS_PARAM_DWORD_SIZE:
> +             ret = sprintf(sysfs_buf, "0x%08X\n",
> +                     be32_to_cpu(*((u32 *)desc_buf)));
> +             break;
> +     case UFS_PARAM_QWORD_SIZE:
> +             ret = sprintf(sysfs_buf, "0x%016llX\n",
> +                     be64_to_cpu(*((u64 *)desc_buf)));
> +             break;
> +     }
> +
> +     return ret;
> +}

Seeing code like this makes me wonder whether this patch series has been 
verified
with sparse? I think sparse will complain about all three be*_to_cpu() casts 
above.
Please use get_unaligned_be*() instead of open-coding these functions.

Thanks,

Bart.

Reply via email to