linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
@ 2021-04-15 13:59 Andy Shevchenko
  2021-04-16  5:17 ` Dan Williams
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-04-15 13:59 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm, linux-acpi, linux-kernel
  Cc: Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown, Andy Shevchenko

Strictly speaking the comparison between guid_t and raw buffer
is not correct. Import GUID to variable of guid_t type and then
compare.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/nfit/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 958aaac869e8..6d8a1a93636a 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -678,10 +678,12 @@ static const char *spa_type_name(u16 type)
 
 int nfit_spa_type(struct acpi_nfit_system_address *spa)
 {
+	guid_t guid;
 	int i;
 
+	import_guid(&guid, spa->range_guid);
 	for (i = 0; i < NFIT_UUID_MAX; i++)
-		if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
+		if (guid_equal(to_nfit_uuid(i), &guid))
 			return i;
 	return -1;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-04-15 13:59 [PATCH v1 1/1] ACPI: NFIT: Import GUID before use Andy Shevchenko
@ 2021-04-16  5:17 ` Dan Williams
  2021-04-16  8:58   ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Williams @ 2021-04-16  5:17 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-nvdimm, Linux ACPI, Linux Kernel Mailing List,
	Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown

On Thu, Apr 15, 2021 at 6:59 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Strictly speaking the comparison between guid_t and raw buffer
> is not correct. Import GUID to variable of guid_t type and then
> compare.

Hmm, what about something like the following instead, because it adds
safety. Any concerns about evaluating x twice in a macro should be
alleviated by the fact that ARRAY_SIZE() will fail the build if (x) is
not an array.

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 8c5dde628405..bac01eec07a6 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -681,7 +681,7 @@ int nfit_spa_type(struct acpi_nfit_system_address *spa)
        int i;

        for (i = 0; i < NFIT_UUID_MAX; i++)
-               if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
+               if (guid_equal(to_nfit_uuid(i), cast_guid(spa->range_guid)))
                        return i;
        return -1;
 }
diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 8cdc0d3567cd..cec1dc2ab994 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -33,6 +33,9 @@ typedef struct {
 extern const guid_t guid_null;
 extern const uuid_t uuid_null;

+#define cast_guid(x) ({ BUILD_BUG_ON(ARRAY_SIZE(x) != 16); (guid_t *)&(x); })
+#define cast_uuid(x) ({ BUILD_BUG_ON(ARRAY_SIZE(x) != 16); (uuid_t *)&(x); })
+
 static inline bool guid_equal(const guid_t *u1, const guid_t *u2)
 {
        return memcmp(u1, u2, sizeof(guid_t)) == 0;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-04-16  5:17 ` Dan Williams
@ 2021-04-16  8:58   ` Andy Shevchenko
  2021-04-16 16:15     ` Dan Williams
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-04-16  8:58 UTC (permalink / raw)
  To: Dan Williams
  Cc: Andy Shevchenko, linux-nvdimm, Linux ACPI,
	Linux Kernel Mailing List, Vishal Verma, Dave Jiang, Ira Weiny,
	Rafael J. Wysocki, Len Brown

On Fri, Apr 16, 2021 at 8:28 AM Dan Williams <dan.j.williams@intel.com> wrote:
>
> On Thu, Apr 15, 2021 at 6:59 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Strictly speaking the comparison between guid_t and raw buffer
> > is not correct. Import GUID to variable of guid_t type and then
> > compare.
>
> Hmm, what about something like the following instead, because it adds
> safety. Any concerns about evaluating x twice in a macro should be
> alleviated by the fact that ARRAY_SIZE() will fail the build if (x) is
> not an array.

ARRAY_SIZE doesn't check type.
I don't like hiding ugly casts like this.


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-04-16  8:58   ` Andy Shevchenko
@ 2021-04-16 16:15     ` Dan Williams
  2021-04-16 17:33       ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Williams @ 2021-04-16 16:15 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andy Shevchenko, linux-nvdimm, Linux ACPI,
	Linux Kernel Mailing List, Vishal Verma, Dave Jiang, Ira Weiny,
	Rafael J. Wysocki, Len Brown

On Fri, Apr 16, 2021 at 1:58 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Fri, Apr 16, 2021 at 8:28 AM Dan Williams <dan.j.williams@intel.com> wrote:
> >
> > On Thu, Apr 15, 2021 at 6:59 AM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > Strictly speaking the comparison between guid_t and raw buffer
> > > is not correct. Import GUID to variable of guid_t type and then
> > > compare.
> >
> > Hmm, what about something like the following instead, because it adds
> > safety. Any concerns about evaluating x twice in a macro should be
> > alleviated by the fact that ARRAY_SIZE() will fail the build if (x) is
> > not an array.
>
> ARRAY_SIZE doesn't check type.

See __must_be_array.

> I don't like hiding ugly casts like this.

See PTR_ERR, ERR_PTR, ERR_CAST.

There's nothing broken about the way the code currently stands, so I'd
rather try to find something to move the implementation forward than
sideways.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-04-16 16:15     ` Dan Williams
@ 2021-04-16 17:33       ` Andy Shevchenko
  2021-04-16 18:04         ` Dan Williams
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-04-16 17:33 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-nvdimm, Linux ACPI, Linux Kernel Mailing List,
	Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown

On Fri, Apr 16, 2021 at 09:15:34AM -0700, Dan Williams wrote:
> On Fri, Apr 16, 2021 at 1:58 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Fri, Apr 16, 2021 at 8:28 AM Dan Williams <dan.j.williams@intel.com> wrote:
> > > On Thu, Apr 15, 2021 at 6:59 AM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > >
> > > > Strictly speaking the comparison between guid_t and raw buffer
> > > > is not correct. Import GUID to variable of guid_t type and then
> > > > compare.
> > >
> > > Hmm, what about something like the following instead, because it adds
> > > safety. Any concerns about evaluating x twice in a macro should be
> > > alleviated by the fact that ARRAY_SIZE() will fail the build if (x) is
> > > not an array.
> >
> > ARRAY_SIZE doesn't check type.
> 
> See __must_be_array.
> 
> > I don't like hiding ugly casts like this.
> 
> See PTR_ERR, ERR_PTR, ERR_CAST.

It's special, i.e. error pointer case. We don't handle such here.

> There's nothing broken about the way the code currently stands, so I'd
> rather try to find something to move the implementation forward than
> sideways.

Submit a patch then. I rest my case b/c I consider that ugly castings worse
than additional API call, although it's not ideal.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-04-16 17:33       ` Andy Shevchenko
@ 2021-04-16 18:04         ` Dan Williams
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2021-04-16 18:04 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-nvdimm, Linux ACPI, Linux Kernel Mailing List,
	Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown

On Fri, Apr 16, 2021 at 10:34 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Fri, Apr 16, 2021 at 09:15:34AM -0700, Dan Williams wrote:
> > On Fri, Apr 16, 2021 at 1:58 AM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Fri, Apr 16, 2021 at 8:28 AM Dan Williams <dan.j.williams@intel.com> wrote:
> > > > On Thu, Apr 15, 2021 at 6:59 AM Andy Shevchenko
> > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > >
> > > > > Strictly speaking the comparison between guid_t and raw buffer
> > > > > is not correct. Import GUID to variable of guid_t type and then
> > > > > compare.
> > > >
> > > > Hmm, what about something like the following instead, because it adds
> > > > safety. Any concerns about evaluating x twice in a macro should be
> > > > alleviated by the fact that ARRAY_SIZE() will fail the build if (x) is
> > > > not an array.
> > >
> > > ARRAY_SIZE doesn't check type.
> >
> > See __must_be_array.
> >
> > > I don't like hiding ugly casts like this.
> >
> > See PTR_ERR, ERR_PTR, ERR_CAST.
>
> It's special, i.e. error pointer case. We don't handle such here.
>
> > There's nothing broken about the way the code currently stands, so I'd
> > rather try to find something to move the implementation forward than
> > sideways.
>
> Submit a patch then. I rest my case b/c I consider that ugly castings worse
> than additional API call, although it's not ideal.

It sounds like you'll NAK that patch, and I'm not too enthusiastic
about these proposed changes either because I disagree that the code
is incorrect. Is there another compromise?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-12-17 18:08 ` Rafael J. Wysocki
@ 2021-12-17 18:37   ` Dan Williams
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Williams @ 2021-12-17 18:37 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Andy Shevchenko, Linux NVDIMM, ACPI Devel Maling List,
	Linux Kernel Mailing List, Vishal Verma, Dave Jiang, Ira Weiny,
	Len Brown

On Fri, Dec 17, 2021 at 10:10 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Mon, Dec 13, 2021 at 9:46 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Strictly speaking the comparison between guid_t and raw buffer
> > is not correct. Import GUID to variable of guid_t type and then
> > compare.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Dan, are you going to take care of this or should I?

I'll take it.

Apologies for the delay in responding. I am still catching up on some
patch merging backlog.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
  2021-12-13 20:46 Andy Shevchenko
@ 2021-12-17 18:08 ` Rafael J. Wysocki
  2021-12-17 18:37   ` Dan Williams
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2021-12-17 18:08 UTC (permalink / raw)
  To: Andy Shevchenko, Dan Williams
  Cc: nvdimm, ACPI Devel Maling List, Linux Kernel Mailing List,
	Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown

On Mon, Dec 13, 2021 at 9:46 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Strictly speaking the comparison between guid_t and raw buffer
> is not correct. Import GUID to variable of guid_t type and then
> compare.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Dan, are you going to take care of this or should I?

> ---
>  drivers/acpi/nfit/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index 7dd80acf92c7..e5d7f2bda13f 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -678,10 +678,12 @@ static const char *spa_type_name(u16 type)
>
>  int nfit_spa_type(struct acpi_nfit_system_address *spa)
>  {
> +       guid_t guid;
>         int i;
>
> +       import_guid(&guid, spa->range_guid);
>         for (i = 0; i < NFIT_UUID_MAX; i++)
> -               if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
> +               if (guid_equal(to_nfit_uuid(i), &guid))
>                         return i;
>         return -1;
>  }
> --
> 2.33.0
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/1] ACPI: NFIT: Import GUID before use
@ 2021-12-13 20:46 Andy Shevchenko
  2021-12-17 18:08 ` Rafael J. Wysocki
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2021-12-13 20:46 UTC (permalink / raw)
  To: Dan Williams, nvdimm, linux-acpi, linux-kernel
  Cc: Vishal Verma, Dave Jiang, Ira Weiny, Rafael J. Wysocki,
	Len Brown, Andy Shevchenko

Strictly speaking the comparison between guid_t and raw buffer
is not correct. Import GUID to variable of guid_t type and then
compare.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/nfit/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 7dd80acf92c7..e5d7f2bda13f 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -678,10 +678,12 @@ static const char *spa_type_name(u16 type)
 
 int nfit_spa_type(struct acpi_nfit_system_address *spa)
 {
+	guid_t guid;
 	int i;
 
+	import_guid(&guid, spa->range_guid);
 	for (i = 0; i < NFIT_UUID_MAX; i++)
-		if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
+		if (guid_equal(to_nfit_uuid(i), &guid))
 			return i;
 	return -1;
 }
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-17 18:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-15 13:59 [PATCH v1 1/1] ACPI: NFIT: Import GUID before use Andy Shevchenko
2021-04-16  5:17 ` Dan Williams
2021-04-16  8:58   ` Andy Shevchenko
2021-04-16 16:15     ` Dan Williams
2021-04-16 17:33       ` Andy Shevchenko
2021-04-16 18:04         ` Dan Williams
2021-12-13 20:46 Andy Shevchenko
2021-12-17 18:08 ` Rafael J. Wysocki
2021-12-17 18:37   ` Dan Williams

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 NNTP newsgroup(s).