diff mbox

mmc: sdhci-pci: Allow for 3 bytes from Intel DSM

Message ID 1492606135-4983-1-git-send-email-adrian.hunter@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Adrian Hunter April 19, 2017, 12:48 p.m. UTC
The DSM used by some Intel controllers can return a 3 byte package. Allow
for that by using memcpy to copy the bytes.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/host/sdhci-pci-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Ulf Hansson April 20, 2017, 2:05 p.m. UTC | #1
On 19 April 2017 at 14:48, Adrian Hunter <adrian.hunter@intel.com> wrote:
> The DSM used by some Intel controllers can return a 3 byte package. Allow
> for that by using memcpy to copy the bytes.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Thanks, applied for next!

Kind regards
Uffe

> ---
>  drivers/mmc/host/sdhci-pci-core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
> index 57d6f50b73dc..eb3e34c7afe2 100644
> --- a/drivers/mmc/host/sdhci-pci-core.c
> +++ b/drivers/mmc/host/sdhci-pci-core.c
> @@ -12,6 +12,7 @@
>   *     - JMicron (hardware and technical support)
>   */
>
> +#include <linux/string.h>
>  #include <linux/delay.h>
>  #include <linux/highmem.h>
>  #include <linux/module.h>
> @@ -413,6 +414,7 @@ static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
>  {
>         union acpi_object *obj;
>         int err = 0;
> +       size_t len;
>
>         obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), intel_dsm_uuid, 0, fn, NULL);
>         if (!obj)
> @@ -423,12 +425,10 @@ static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
>                 goto out;
>         }
>
> -       if (obj->buffer.length >= 4)
> -               *result = *(u32 *)obj->buffer.pointer;
> -       else if (obj->buffer.length >= 2)
> -               *result = *(u16 *)obj->buffer.pointer;
> -       else
> -               *result = *(u8 *)obj->buffer.pointer;
> +       len = min_t(size_t, obj->buffer.length, 4);
> +
> +       *result = 0;
> +       memcpy(result, obj->buffer.pointer, len);
>  out:
>         ACPI_FREE(obj);
>
> --
> 1.9.1
>
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 57d6f50b73dc..eb3e34c7afe2 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -12,6 +12,7 @@ 
  *     - JMicron (hardware and technical support)
  */
 
+#include <linux/string.h>
 #include <linux/delay.h>
 #include <linux/highmem.h>
 #include <linux/module.h>
@@ -413,6 +414,7 @@  static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
 {
 	union acpi_object *obj;
 	int err = 0;
+	size_t len;
 
 	obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), intel_dsm_uuid, 0, fn, NULL);
 	if (!obj)
@@ -423,12 +425,10 @@  static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
 		goto out;
 	}
 
-	if (obj->buffer.length >= 4)
-		*result = *(u32 *)obj->buffer.pointer;
-	else if (obj->buffer.length >= 2)
-		*result = *(u16 *)obj->buffer.pointer;
-	else
-		*result = *(u8 *)obj->buffer.pointer;
+	len = min_t(size_t, obj->buffer.length, 4);
+
+	*result = 0;
+	memcpy(result, obj->buffer.pointer, len);
 out:
 	ACPI_FREE(obj);