ACPI: NFIT: Import GUID before use
Subsystems (3)
Andy Shevchenko
reviewerPATCH 1/1 ACPI: NFIT: Import GUID before use
Strictly speaking the comparison between guid_t and raw buffer is not correct. Import GUID to variable of guid_t type and then compare.
--- drivers/acpi/nfit/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/nfit/core.c +3 -1
@@ -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 ; }
Signature · 1 line
2.30.2
Quoted 4 lines · Andy Shevchenko
Strictly speaking the comparison between
guid_tand raw buffer is not correct. Import GUID to variable ofguid_ttype 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.
drivers/acpi/nfit/core.c +1 -1
@@ -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 ; }
include/linux/uuid.h +3 -0
@@ -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 ;
Quoted 4 lines · Dan Williams
Quoted 1 line · Andy Shevchenko
Quoted 8 lines
Quoted 3 lines
Strictly speaking the comparison between
guid_tand raw buffer is not correct. Import GUID to variable ofguid_ttype 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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Dan Williams
Quoted 4 lines · Andy Shevchenko
Strictly speaking the comparison between
guid_tand raw buffer is not correct. Import GUID to variable ofguid_ttype and then compare.
Quoted 6 lines
Quoted 4 lines
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_SIZEdoesn't check type.
See __must_be_array.
Quoted 1 line
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.
Quoted 15 lines · Dan Williams
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Dan Williams
Quoted 4 lines · Andy Shevchenko
Strictly speaking the comparison between
guid_tand raw buffer is not correct. Import GUID to variable ofguid_ttype 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.
Quoted 7 lines
Quoted 1 line
ARRAY_SIZEdoesn't check type.See
__must_be_array.Quoted 1 line
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.
Quoted 3 lines
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 25 lines · Andy Shevchenko
Quoted 15 lines · Dan Williams
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Dan Williams
Quoted 4 lines · Andy Shevchenko
Strictly speaking the comparison between
guid_tand raw buffer is not correct. Import GUID to variable ofguid_ttype 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.Quoted 7 lines
Quoted 1 line
ARRAY_SIZEdoesn't check type.See
__must_be_array.Quoted 1 line
I don't like hiding ugly casts like this.
See
PTR_ERR,ERR_PTR,ERR_CAST.
Quoted 8 lines
It's special, i.e. error pointer case. We don't handle such here.
Quoted 3 lines
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?