Linux-ACPI Archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Rithvik Rama <rithvik.rama@gmail.com>
Cc: rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Tony Luck <tony.luck@intel.com>,
	 Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH] ACPI/ADXL: Added function for ADXL DSM Function 3
Date: Fri, 26 Apr 2024 19:25:17 +0200	[thread overview]
Message-ID: <CAJZ5v0heV36XbRy8TynZuB_sLTKHQDPTiuG_KxX=yYoF4oU0Yg@mail.gmail.com> (raw)
In-Reply-To: <20240331051126.10024-1-rithvik.rama@gmail.com>

On Sun, Mar 31, 2024 at 7:11 AM Rithvik Rama <rithvik.rama@gmail.com> wrote:
>
> Current driver supports only Function Index 1 & 2 as mentioned in the
> ACPI ADXL DSM Interface. Added a function for ACPI Function Index 3.

What's happened that it has become useful now?

Who's going to use it and for what purpose?

> Signed-off-by: Rithvik Rama <rithvik.rama@gmail.com>
> ---
>  drivers/acpi/acpi_adxl.c | 54 +++++++++++++++++++++++++++++++++++++++-
>  include/linux/adxl.h     |  1 +
>  2 files changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/acpi_adxl.c b/drivers/acpi/acpi_adxl.c
> index 13c8f7b50c46..5bf53662b737 100644
> --- a/drivers/acpi/acpi_adxl.c
> +++ b/drivers/acpi/acpi_adxl.c
> @@ -14,6 +14,7 @@
>  #define ADXL_REVISION                  0x1
>  #define ADXL_IDX_GET_ADDR_PARAMS       0x1
>  #define ADXL_IDX_FORWARD_TRANSLATE     0x2
> +#define ADXL_IDX_REVERSE_TRANSLATE     0X3
>  #define ACPI_ADXL_PATH                 "\\_SB.ADXL"
>
>  /*
> @@ -135,6 +136,56 @@ int adxl_decode(u64 addr, u64 component_values[])
>  }
>  EXPORT_SYMBOL_GPL(adxl_decode);
>
> +/**
> + * adxl_reverse_decode - Ask BIOS to decode a memory address to system address
> + * @component_values: pointer to array of values for each component
> + * Returns 0 on success, negative error code otherwise
> + *

Redundant line.

> + */
> +
> +int adxl_reverse_decode(u64 component_values[])
> +{
> +       union acpi_object *argv4, *results, *r;
> +       int i, cnt;
> +
> +       argv4 = kzalloc((adxl_count+1)*sizeof(*argv4), GFP_KERNEL);

kcalloc()?

> +       if (!argv4)
> +               return -ENOMEM;
> +
> +       if (!adxl_component_names)
> +               return -EOPNOTSUPP;

This could be checked before allocating memory which is now leaked if
it is NULL.

This function generally leaks the argv4 memory AFAICS.

> +
> +       argv4[0].type = ACPI_TYPE_PACKAGE;
> +       argv4[0].package.count = adxl_count;
> +       argv4[0].package.elements = &argv4[1];
> +
> +       /*
> +        * Loop through supported memory component values
> +        */
> +       for (i = 1; i <= adxl_count; i++) {
> +               argv4[i].integer.type = ACPI_TYPE_INTEGER;
> +               argv4[i].integer.value = component_values[i-1];
> +       }
> +
> +       results = adxl_dsm(ADXL_IDX_REVERSE_TRANSLATE, argv4);
> +       if (!results)
> +               return -EINVAL;
> +
> +       r = results->package.elements + 1;
> +       cnt = r->package.count;
> +       if (cnt != adxl_count) {
> +               ACPI_FREE(results);
> +               return -EINVAL;
> +       }
> +       r = r->package.elements;
> +       for (i = 0; i < cnt; i++)
> +               component_values[i] = r[i].integer.value;
> +
> +       ACPI_FREE(results);
> +       return 0;
> +}
> +EXPORT_SYMBOL_GPL(adxl_reverse_decode);

No users of this are being added.

For this to be applicable, you need to also submit a patch adding a
caller of adxl_reverse_decode().

> +
>  static int __init adxl_init(void)
>  {
>         char *path = ACPI_ADXL_PATH;
> @@ -155,7 +206,8 @@ static int __init adxl_init(void)
>
>         if (!acpi_check_dsm(handle, &adxl_guid, ADXL_REVISION,
>                             ADXL_IDX_GET_ADDR_PARAMS |
> -                           ADXL_IDX_FORWARD_TRANSLATE)) {
> +                           ADXL_IDX_FORWARD_TRANSLATE |
> +                           ADXL_IDX_REVERSE_TRANSLATE)) {
>                 pr_info("DSM method does not support forward translate\n");
>                 return -ENODEV;
>         }
> diff --git a/include/linux/adxl.h b/include/linux/adxl.h
> index 2a629acb4c3f..f3fea64a270c 100644
> --- a/include/linux/adxl.h
> +++ b/include/linux/adxl.h
> @@ -9,5 +9,6 @@
>
>  const char * const *adxl_get_component_names(void);
>  int adxl_decode(u64 addr, u64 component_values[]);
> +int adxl_reverse_decode(u64 component_values[]);
>
>  #endif /* _LINUX_ADXL_H */
> --

      reply	other threads:[~2024-04-26 17:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-31  5:11 [PATCH] ACPI/ADXL: Added function for ADXL DSM Function 3 Rithvik Rama
2024-04-26 17:25 ` Rafael J. Wysocki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJZ5v0heV36XbRy8TynZuB_sLTKHQDPTiuG_KxX=yYoF4oU0Yg@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=bp@alien8.de \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rithvik.rama@gmail.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).