lib/uuid: Introduce uuid_{be|le}_cmp_p{p}() helpers
Andy Shevchenko
reviewerPATCH 1/8 lib/uuid: Introduce uuid_{be|le}_cmp_p{p}() helpers
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and, in some cases, a type casting.
--- include/linux/uuid.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/linux/uuid.h +20 -0
@@ -58,6 +58,26 @@ static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)return memcmp (&u1, &u2,sizeof (uuid_be)); } +static inline int uuid_le_cmp_p (const uuid_le *pu1,const uuid_le u2) +{ +return memcmp (pu1, &u2,sizeof (uuid_le)); +} + +static inline int uuid_be_cmp_p (const uuid_be *pu1,const uuid_be u2) +{ +return memcmp (pu1, &u2,sizeof (uuid_be)); +} + +static inline int uuid_le_cmp_pp (const uuid_le *pu1,const uuid_le *pu2) +{ +return memcmp (pu1, pu2,sizeof (uuid_le)); +} + +static inline int uuid_be_cmp_pp (const uuid_be *pu1,const uuid_be *pu2) +{ +return memcmp (pu1, pu2,sizeof (uuid_be)); +} +void generate_random_uuid (unsigned char uuid[16 ]);extern void uuid_le_gen (uuid_le *u);
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 2/8 ASoC: Intel: Skylake: Use recently introduced uuid_le_cmp_p{p}()
Recently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- sound/soc/intel/skylake/skl-pcm.c | 2 +- sound/soc/intel/skylake/skl-sst-utils.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/intel/skylake/skl-pcm.c +1 -1
@@ -1207,7 +1207,7 @@ static int skl_get_module_info(struct skl *skl, struct skl_module_cfg *mconfig) }list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) { mconfig->id.module_id = module->id; mconfig->is_loadable = module->is_loadable;return 0 ;
sound/soc/intel/skylake/skl-sst-utils.c +2 -2
@@ -189,7 +189,7 @@ int skl_get_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int instance_id)int pvt_id;list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) { pvt_id =skl_pvtid_128 (module);if (pvt_id >=0 ) {
@@ -218,7 +218,7 @@ int skl_put_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int *pvt_id)struct uuid_module *module;list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) {if (*pvt_id !=0 ) i = (*pvt_id) /64 ;
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 3/8 HID: intel_ish-hid: Use recently introduced uuid_le_cmp_p{p}()
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/hid/intel-ish-hid/ishtp/bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/intel-ish-hid/ishtp/bus.c +1 -2
@@ -138,8 +138,7 @@ int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)int i, res = -ENOENT ;for (i =0 ; i < dev->fw_clients_num; ++i) { -if (uuid_le_cmp (*uuid, dev->fw_clients[i].props.protocol_name) - ==0 ) { +if (!uuid_le_cmp_p (uuid, dev->fw_clients[i].props.protocol_name)) { res = i;break ; }
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 4/8 vfio-mdev: Use recently introduced uuid_le_cmp_p{p}()
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/vfio/mdev/mdev_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/mdev/mdev_core.c +1 -1
@@ -75,7 +75,7 @@ static int _find_mdev_device(struct device *dev, void *data) mdev =to_mdev_device (dev); -if (uuid_le_cmp (mdev->uuid, *(uuid_le *)data) ==0 ) +if (uuid_le_cmp_p (data, mdev->uuid) ==0 )return 1 ;return 0 ;
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 5/8 vmbus: Use recently introduced uuid_le_cmp_p{p}() helpers
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/hv/channel_mgmt.c | 10 +++++----- drivers/hv/vmbus_drv.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/hv/channel_mgmt.c +5 -5
@@ -176,7 +176,7 @@ static bool is_unsupported_vmbus_devs(const uuid_le *guid)int i;for (i =0 ; i <ARRAY_SIZE (vmbus_unsupported_devs); i++) -if (!uuid_le_cmp (*guid, vmbus_unsupported_devs[i].guid)) +if (!uuid_le_cmp_p (guid, vmbus_unsupported_devs[i].guid))return true;return false; }
@@ -190,7 +190,7 @@ static u16 hv_get_dev_type(const struct vmbus_channel *channel)return HV_UNKNOWN ;for (i =HV_IDE ; i <HV_UNKNOWN ; i++) { -if (!uuid_le_cmp (*guid, vmbus_devs[i].guid)) +if (!uuid_le_cmp_p (guid, vmbus_devs[i].guid))return i; }pr_info ("Unknown GUID: %pUl\n" , guid);
@@ -456,9 +456,9 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)list_for_each_entry (channel, &vmbus_connection.chn_list, listentry) {if (!uuid_le_cmp (channel->offermsg.offer.if_type, - newchannel->offermsg.offer.if_type) && - !uuid_le_cmp (channel->offermsg.offer.if_instance, - newchannel->offermsg.offer.if_instance)) { + newchannel->offermsg.offer.if_type) && + !uuid_le_cmp (channel->offermsg.offer.if_instance, + newchannel->offermsg.offer.if_instance)) { fnew = false;break ; }
drivers/hv/vmbus_drv.c +1 -1
@@ -557,7 +557,7 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv,/* Look at the dynamic ids first, before the static ones */ spin_lock (&drv->dynids.lock);list_for_each_entry (dynid, &drv->dynids.list, node) { -if (!uuid_le_cmp (dynid->id.guid, *guid)) { +if (!uuid_le_cmp_p (guid, dynid->id.guid)) { id = &dynid->id;break ; }
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 6/8 mei: Use recently introduced uuid_le_cmp_p{p}() helpers
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/misc/mei/bus-fixup.c | 2 +- drivers/misc/mei/bus.c | 2 +- drivers/misc/mei/client.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/misc/mei/bus-fixup.c +1 -1
@@ -416,7 +416,7 @@ void mei_cl_bus_dev_fixup(struct mei_cl_device *cldev) f = &mei_fixups[i];if (uuid_le_cmp (f->uuid,MEI_UUID_ANY ) ==0 || -uuid_le_cmp (f->uuid, *uuid) ==0 ) +uuid_le_cmp_p (uuid, f->uuid) ==0 ) f->hook (cldev); } }
drivers/misc/mei/bus.c +1 -1
@@ -615,7 +615,7 @@ struct mei_cl_device_id *mei_cl_device_find(struct mei_cl_device *cldev, id = cldrv->id_table;while (uuid_le_cmp (NULL_UUID_LE , id->uuid)) { -if (!uuid_le_cmp (*uuid, id->uuid)) { +if (!uuid_le_cmp_p (uuid, id->uuid)) { match = true;if (cldev->name[0 ])
drivers/misc/mei/client.c +2 -2
@@ -148,7 +148,7 @@ static struct mei_me_client *__mei_me_cl_by_uuid(struct mei_device *dev,list_for_each_entry (me_cl, &dev->me_clients, list) { pn = &me_cl->props.protocol_name; -if (uuid_le_cmp (*uuid, *pn) ==0 ) +if (uuid_le_cmp_pp (uuid, pn) ==0 )return mei_me_cl_get (me_cl); }
@@ -228,7 +228,7 @@ static struct mei_me_client *__mei_me_cl_by_uuid_id(struct mei_device *dev,list_for_each_entry (me_cl, &dev->me_clients, list) { pn = &me_cl->props.protocol_name; -if (uuid_le_cmp (*uuid, *pn) ==0 && +if (uuid_le_cmp_pp (uuid, pn) ==0 && me_cl->client_id == client_id)return mei_me_cl_get (me_cl); }
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 7/8 efi: Use recently introduced uuid_le_cmp_p{p}() helpers
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/firmware/efi/cper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/efi/cper.c +3 -3
@@ -402,14 +402,14 @@ static void cper_estatus_print_section(printk ("%s""fru_text: %.20s\n" , pfx, gdata->fru_text);snprintf (newpfx,sizeof (newpfx),"%s%s" , pfx,INDENT_SP ); -if (!uuid_le_cmp (*sec_type,CPER_SEC_PROC_GENERIC )) { +if (!uuid_le_cmp_p (sec_type,CPER_SEC_PROC_GENERIC )) {struct cper_sec_proc_generic *proc_err = (void *)(gdata +1 );printk ("%s""section_type: general processor error\n" , newpfx);if (gdata->error_data_length >=sizeof (*proc_err))cper_print_proc_generic (newpfx, proc_err);else goto err_section_too_small; - }else if (!uuid_le_cmp (*sec_type,CPER_SEC_PLATFORM_MEM )) { + }else if (!uuid_le_cmp_p (sec_type,CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem_err = (void *)(gdata +1 );printk ("%s""section_type: memory error\n" , newpfx); if (gdata->error_data_length >=
@@ -418,7 +418,7 @@ static void cper_estatus_print_section( gdata->error_data_length); else goto err_section_too_small; - }else if (!uuid_le_cmp (*sec_type,CPER_SEC_PCIE )) { + }else if (!uuid_le_cmp_p (sec_type,CPER_SEC_PCIE )) {struct cper_sec_pcie *pcie = (void *)(gdata +1 );printk ("%s""section_type: PCIe error\n" , newpfx);if (gdata->error_data_length >=sizeof (*pcie))
Signature · 1 line
2.11.0
Andy Shevchenko
reviewerPATCH 8/8 ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers
In reply to Andy ShevchenkoRecently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
--- drivers/acpi/acpi_extlog.c | 2 +- drivers/acpi/apei/ghes.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/acpi_extlog.c +1 -1
@@ -169,7 +169,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,if (gdata->validation_bits &CPER_SEC_VALID_FRU_TEXT ) fru_text = gdata->fru_text; sec_type = (uuid_le *)gdata->section_type; -if (!uuid_le_cmp (*sec_type,CPER_SEC_PLATFORM_MEM )) { +if (!uuid_le_cmp_p (sec_type,CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem = (void *)(gdata +1 );if (gdata->error_data_length >=sizeof (*mem)) trace_extlog_mem_event(mem, err_seq, fru_id, fru_text,
drivers/acpi/apei/ghes.c +4 -4
@@ -431,12 +431,13 @@ static void ghes_do_proc(struct ghes *ghes, {int sev, sec_sev;struct acpi_hest_generic_data *gdata; +uuid_le *sec_type; sev =ghes_severity (estatus->error_severity);apei_estatus_for_each_section (estatus, gdata) { + sec_type = (uuid_le *)gdata->section_type; sec_sev =ghes_severity (gdata->error_severity); -if (!uuid_le_cmp (*(uuid_le *)gdata->section_type, -CPER_SEC_PLATFORM_MEM )) { +if (!uuid_le_cmp_p (sec_type,CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem_err; mem_err = (struct cper_sec_mem_err *)(gdata+1 );ghes_edac_report_mem_error (ghes, sev, mem_err);
@@ -445,8 +446,7 @@ static void ghes_do_proc(struct ghes *ghes,ghes_handle_memory_failure (gdata, sev); }#ifdef CONFIG_ACPI_APEI_PCIEAER - else if (!uuid_le_cmp(*(uuid_le *)gdata->section_type, -CPER_SEC_PCIE )) { + else if (!uuid_le_cmp_p(sec_type, CPER_SEC_PCIE)) {struct cper_sec_pcie *pcie_err; pcie_err = (struct cper_sec_pcie *)(gdata+1 ); if (sev == GHES_SEV_RECOVERABLE &&
Signature · 1 line
2.11.0
Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers
Quoted 17 lines · Andy Shevchenko
Recently introduced helpers take pointers to uuid_{be|le} instead of reference.
Using them makes code less ugly.
Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/acpi/acpi_extlog.c | 2 +- drivers/acpi/apei/ghes.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/acpi/acpi_extlog.c +0
-0
drivers/acpi/acpi_extlog.c static int extlog_print(struct notifier_block *nb, unsigned long val, · line 175
Quoted 8 lines
drivers/acpi/acpi_extlog.c +1
-1@@ -169,7 +169,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,if (gdata->validation_bits &CPER_SEC_VALID_FRU_TEXT ) fru_text = gdata->fru_text; sec_type = (uuid_le *)gdata->section_type; -if (!uuid_le_cmp (*sec_type,CPER_SEC_PLATFORM_MEM )) { +if (!uuid_le_cmp_p (sec_type,CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem = (void *)(gdata +1 );if (gdata->error_data_length >=sizeof (*mem)) trace_extlog_mem_event(mem, err_seq, fru_id, fru_text,
ACK for this one.
Quoted 22 lines
drivers/acpi/apei/ghes.c +3
-2@@ -431,12 +431,13 @@ static void ghes_do_proc(struct ghes *ghes, {int sev, sec_sev;struct acpi_hest_generic_data *gdata; +uuid_le *sec_type; sev =ghes_severity (estatus->error_severity);apei_estatus_for_each_section (estatus, gdata) { + sec_type = (uuid_le *)gdata->section_type; sec_sev =ghes_severity (gdata->error_severity); -if (!uuid_le_cmp (*(uuid_le *)gdata->section_type, -CPER_SEC_PLATFORM_MEM )) { +if (!uuid_le_cmp_p (sec_type,CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem_err; mem_err = (struct cper_sec_mem_err *)(gdata+1 );ghes_edac_report_mem_error (ghes, sev, mem_err);
drivers/acpi/apei/ghes.c static void ghes_do_proc(struct ghes *ghes, · line 452
Quoted 9 lines
drivers/acpi/apei/ghes.c +1
-2@@ -445,8 +446,7 @@ static void ghes_do_proc(struct ghes *ghes,ghes_handle_memory_failure (gdata, sev); }#ifdef CONFIG_ACPI_APEI_PCIEAER - else if (!uuid_le_cmp(*(uuid_le *)gdata->section_type, -CPER_SEC_PCIE )) { + else if (!uuid_le_cmp_p(sec_type, CPER_SEC_PCIE)) {struct cper_sec_pcie *pcie_err; pcie_err = (struct cper_sec_pcie *)(gdata+1 ); if (sev == GHES_SEV_RECOVERABLE &&
But this one is for Boris.
Thanks,
Rafael
Quoted 42 lines
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and, in some cases, a type casting.
Cc Andrew Morton <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Cc Vinod Koul <[email protected]>Cc Srinivas Pandruvada <[email protected]>Cc Benjamin Tissoires <[email protected]>Cc Kirti Wankhede <[email protected]>Cc Alex Williamson <[email protected]>Cc "K. Y. Srinivasan" <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc Tomas Winkler <[email protected]>Cc Matt Fleming <[email protected]>Cc Ard Biesheuvel <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- include/linux/uuid.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)include/linux/uuid.h index renamed from include/linux/uuid.h +0
-0
4dff73a89758..45312cb5ac65100644include/linux/uuid.h +7
-0@@ -58,6 +58,26 @@ static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)return memcmp (&u1, &u2,sizeof (uuid_be)); } +static inline int uuid_le_cmp_p (const uuid_le *pu1,const uuid_le u2) { +return memcmp (pu1, &u2,sizeof (uuid_le)); } + +static inline int uuid_be_cmp_p (const uuid_be *pu1,const uuid_be u2) { +return memcmp (pu1, &u2,sizeof (uuid_be)); } + +static inline int uuid_le_cmp_pp(const uuid_le *pu1, const uuid_le
include/linux/uuid.h static inline int uuid_be_cmp(const uuid_be u1, const · line 77
Quoted 10 lines
include/linux/uuid.h +7
-0+*pu2) { +return memcmp (pu1, pu2,sizeof (uuid_le)); } + +static inline int uuid_be_cmp_pp (const uuid_be *pu1,const uuid_be +*pu2) { +return memcmp (pu1, pu2,sizeof (uuid_be)); } +void generate_random_uuid (unsigned char uuid[16 ]);extern void uuid_le_gen (uuid_le *u);
I think this going overboard, the _pp types are just enough. Tomas
Quoted 6 lines · Tomas
Quoted 4 lines
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and, in some cases, a type casting.
I think this going overboard, the
_pptypes are just enough.
I looked at existing users and there are cases like #define XXX_UUID UUID_...(a, b, c, ...)
uuid_.*_cmp(value, XXX_UUID)
For _pp variant if would be _cmp_pp(value, &XXX_UUID) which is slightly worse than for _p variant.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Tomas
Quoted 5 lines
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and,
in some cases, a type casting.I think this going overboard, the
_pptypes are just enough.
Quoted 7 lines
I looked at existing users and there are cases like #define
XXX_UUIDUUID_...(a, b, c, ...)uuid_.*_cmp(value,
XXX_UUID)For
_ppvariant if would be_cmp_pp(value, &XXX_UUID)which is slightly worse than for _p variant.
Maybe it's worth to actually replace the defines with variables than to create an interface with all the permutations.
Tomas
Re: [PATCH v1 2/8] ASoC: Intel: Skylake: Use recently introduced uuid_le_cmp_p{p}()
In reply to Andy ShevchenkoQuoted 2 lines · Andy Shevchenko
Recently introduced helpers take pointers to uuid_{be|le} instead of reference.
Are they in linus's tree, if not it introduces dependency, so we might want to defer after merge window
Quoted 2 lines
Using them makes code less ugly.
How so..?
Quoted 48 lines
Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Cc Vinod Koul <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- sound/soc/intel/skylake/skl-pcm.c | 2 +- sound/soc/intel/skylake/skl-sst-utils.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)sound/soc/intel/skylake/skl-pcm.c +1
-1@@ -1207,7 +1207,7 @@ static int skl_get_module_info(struct skl *skl, struct skl_module_cfg *mconfig) }list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) { mconfig->id.module_id = module->id; mconfig->is_loadable = module->is_loadable;return 0 ;sound/soc/intel/skylake/skl-sst-utils.c +2
-2@@ -189,7 +189,7 @@ int skl_get_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int instance_id)int pvt_id;list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) { pvt_id =skl_pvtid_128 (module);if (pvt_id >=0 ) {@@ -218,7 +218,7 @@ int skl_put_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int *pvt_id)struct uuid_module *module;list_for_each_entry (module, &ctx->uuid_list, list) { -if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) {if (*pvt_id !=0 ) i = (*pvt_id) /64 ;Signature · 1 line
2.11.0
Signature · 1 line
~Vinod
Andy Shevchenko
reviewerRe: [PATCH v1 2/8] ASoC: Intel: Skylake: Use recently introduced uuid_le_cmp_p{p}()
Quoted 7 lines · Vinod Koul
Quoted 2 lines · Andy Shevchenko
Recently introduced helpers take pointers to uuid_{be|le} instead of reference.
Are they in linus's tree, if not it introduces dependency, so we might want
to defer after merge window
You are Cc'ed to patch 1 which brings them.
Quoted 4 lines
Quoted 2 lines
Using them makes code less ugly.
How so..?
Consider below example.
- if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) {
+ if (uuid_le_cmp_p(uuid_mod, module->uuid) == 0) {
There are two points:
1) caller don't need to dereference pointers to its values;
2) this allow compiler to not copy the data (though clever compiler might optimize that).
Quoted 56 lines
Quoted 54 lines
Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Cc Vinod Koul <[email protected]>---
sound/soc/intel/skylake/skl-pcm.c | 2 +-
sound/soc/intel/skylake/skl-sst-utils.c | 4 ++--2 files changed, 3 insertions(+), 3 deletions(-)sound/soc/intel/skylake/skl-pcm.c +0
-0@@ -1207,7 +1207,7 @@ static int skl_get_module_info(struct skl *skl, struct skl_module_cfg *mconfig) }
list_for_each_entry(module, &ctx->uuid_list, list){sound/soc/intel/skylake/skl-pcm.c +1
-1-if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) {
mconfig->id.module_id=module->id;mconfig->is_loadable=module->is_loadable; return 0;sound/soc/intel/skylake/skl-sst-utils.c +0
-0@@ -189,7 +189,7 @@ int skl_get_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int instance_id) int pvt_id;
list_for_each_entry(module, &ctx->uuid_list, list){sound/soc/intel/skylake/skl-sst-utils.c +1
-1-if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) {
pvt_id=skl_pvtid_128(module); if (pvt_id>= 0) {sound/soc/intel/skylake/skl-sst-utils.c +0
-0@@ -218,7 +218,7 @@ int skl_put_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int *pvt_id) struct uuid_module *module;
list_for_each_entry(module, &ctx->uuid_list, list){sound/soc/intel/skylake/skl-sst-utils.c +1
-1-if (uuid_le_cmp (*uuid_mod, module->uuid) ==0 ) { +if (uuid_le_cmp_p (uuid_mod, module->uuid) ==0 ) {
if (*pvt_id!= 0)
i = (*pvt_id) / 64; --
2.11.0
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Andy Shevchenko
reviewerQuoted 17 lines · Tomas
Quoted 16 lines · Andy Shevchenko
Quoted 7 lines · Tomas
Quoted 5 lines
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and,
in some cases, a type casting.I think this going overboard, the
_pptypes are just enough.I looked at existing users and there are cases like #define
XXX_UUIDUUID_...(a, b, c, ...)uuid_.*_cmp(value,
XXX_UUID)
Quoted 7 lines
Quoted 2 lines
For
_ppvariant if would be_cmp_pp(value, &XXX_UUID)which is slightly worse than for _p variant.Maybe it's worth to actually replace the defines with variables than to
create an interface with all the permutations.
Maybe. I didn't estimate the number of users that would be in a scope.
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Quoted 42 lines
New helpers take pointers to uuid_{be|le} as parameters.
When using them on a raw data we don't need to do an ugly dereference and, in some cases, a type casting.
Cc Andrew Morton <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Cc Vinod Koul <[email protected]>Cc Srinivas Pandruvada <[email protected]>Cc Benjamin Tissoires <[email protected]>Cc Kirti Wankhede <[email protected]>Cc Alex Williamson <[email protected]>Cc "K. Y. Srinivasan" <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc Tomas Winkler <[email protected]>Cc Matt Fleming <[email protected]>Cc Ard Biesheuvel <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- include/linux/uuid.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)include/linux/uuid.h index renamed from include/linux/uuid.h +0
-0
4dff73a89758..45312cb5ac65100644include/linux/uuid.h +7
-0@@ -58,6 +58,26 @@ static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)return memcmp (&u1, &u2,sizeof (uuid_be)); } +static inline int uuid_le_cmp_p (const uuid_le *pu1,const uuid_le u2) { +return memcmp (pu1, &u2,sizeof (uuid_le)); } + +static inline int uuid_be_cmp_p (const uuid_be *pu1,const uuid_be u2) { +return memcmp (pu1, &u2,sizeof (uuid_be)); } + +static inline int uuid_le_cmp_pp(const uuid_le *pu1, const uuid_le
include/linux/uuid.h static inline int uuid_be_cmp(const uuid_be u1, const · line 77
Quoted 10 lines
include/linux/uuid.h +7
-0+*pu2) { +return memcmp (pu1, pu2,sizeof (uuid_le)); } + +static inline int uuid_be_cmp_pp (const uuid_be *pu1,const uuid_be +*pu2) { +return memcmp (pu1, pu2,sizeof (uuid_be)); } +void generate_random_uuid (unsigned char uuid[16 ]);extern void uuid_le_gen (uuid_le *u);
There's a bug in gcc wherein constant compound literals are generated on the stack at runtime, rather than stored in rodata. The bug occurs if the compound literal is passed by reference. It does not manifest itself when passing by value:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68725
Hence this patch is unfortunately counterproductive if the UUIDs are declared const.
FWIW I've posted a series back in January to constify UUIDs as much as possible, but I got some objections and lacked the time so far to address them. In fact I'm thinking that gcc needs to be fixed first, then we can focus on improving the kernel side of things:
https://www.spinics.net/lists/linux-efi/msg10093.html
Best regards,
Lukas
Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
drivers/acpi/apei/ghes.c static void ghes_do_proc(struct ghes *ghes, · line 452
Quoted 8 lines
#ifdef
CONFIG_ACPI_APEI_PCIEAERdrivers/acpi/apei/ghes.c +1
-2-else if (!uuid_le_cmp (*(uuid_le *)gdata->section_type, -CPER_SEC_PCIE )) { +else if (!uuid_le_cmp_p (sec_type,CPER_SEC_PCIE )) {struct cper_sec_pcie *pcie_err; pcie_err = (struct cper_sec_pcie *)(gdata+1 ); if (sev == GHES_SEV_RECOVERABLE &&But this one is for Boris.
I don't see anything wrong with it upon a brief inspection.
What could be improved here, though, is if the whole uuid_* types handling be changed so that gcc doesn't generate yucky code. Because here's what it does now, regardless of this patch:
.file 16 "./include/linux/uuid.h"
.loc 16 63 0
leaq 16(%rsp), %rsi #,
movl $16, %edx #,
movq %r15, %rdi # gdata,
movb $84, 16(%rsp) #, MEM[(struct *)&u2]
movb $-23, 17(%rsp) #, MEM[(struct *)&u2 + 1B]
movb $-107, 18(%rsp) #, MEM[(struct *)&u2 + 2B]
movb $-39, 19(%rsp) #, MEM[(struct *)&u2 + 3B]
movb $-63, 20(%rsp) #, MEM[(struct *)&u2 + 4B]
movb $-69, 21(%rsp) #, MEM[(struct *)&u2 + 5B]
movb $15, 22(%rsp) #, MEM[(struct *)&u2 + 6B]
movb $67, 23(%rsp) #, MEM[(struct *)&u2 + 7B]
movb $-83, 24(%rsp) #, MEM[(struct *)&u2 + 8B]
movb $-111, 25(%rsp) #, MEM[(struct *)&u2 + 9B]
movb $-76, 26(%rsp) #, MEM[(struct *)&u2 + 10B]
movb $77, 27(%rsp) #, MEM[(struct *)&u2 + 11B]
movb $-53, 28(%rsp) #, MEM[(struct *)&u2 + 12B]
movb $60, 29(%rsp) #, MEM[(struct *)&u2 + 13B]
movb $111, 30(%rsp) #, MEM[(struct *)&u2 + 14B]
movb $53, 31(%rsp) #, MEM[(struct *)&u2 + 15B]
call memcmp #So it is basically building that UUID byte by byte before calling memcmp.
And I'm wondering if those 16-byte arrays could be replaced with
typedef struct {
u64 a, b;
} u128;from the crypto code.
And whether the code generated by gcc would look much saner. Because the CPU can handle two qwords much better/faster than 16 u8s.
Anyway, in case someone feels bored...
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- Andy Shevchenko
reviewerRe: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers
Quoted 15 lines · Borislav Petkov
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines
#ifdef
CONFIG_ACPI_APEI_PCIEAER(quoted diff) +0
-1- else if (!uuid_le_cmp(*(uuid_le *)gdata-Quoted 1 line
section_type,(quoted diff) +1
-1- CPER_SEC_PCIE)) { + else if (!uuid_le_cmp_p(sec_type, CPER_SEC_PCIE)){
structcper_sec_pcie*pcie_err;pcie_err= (structcper_sec_pcie*)(gdata+1);
if (sev ==GHES_SEV_RECOVERABLE&&But this one is for Boris.
Quoted 1 line
I don't see anything wrong with it upon a brief inspection.
Lukas pointed to this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68725
Quoted 51 lines
What could be improved here, though, is if the whole uuid_* types handling be changed so that gcc doesn't generate yucky code. Because here's what it does now, regardless of this patch:
.file 16 "
./include/linux/uuid.h"
.loc 16 63 0
leaq 16(%rsp), %rsi #,
movl $16, %edx #,
movq %r15, %rdi # gdata,
movb $84, 16(%rsp) #, MEM[(struct *)&u2] movb $-23, 17(%rsp) #, MEM[(struct *)&u2 + 1B] movb $-107, 18(%rsp) #, MEM[(struct *)&u2 + 2B] movb $-39, 19(%rsp) #, MEM[(struct *)&u2 + 3B] movb $-63, 20(%rsp) #, MEM[(struct *)&u2 + 4B] movb $-69, 21(%rsp) #, MEM[(struct *)&u2 + 5B] movb $15, 22(%rsp) #, MEM[(struct *)&u2 + 6B] movb $67, 23(%rsp) #, MEM[(struct *)&u2 + 7B] movb $-83, 24(%rsp) #, MEM[(struct *)&u2 + 8B] movb $-111, 25(%rsp) #, MEM[(struct *)&u2 + 9B] movb $-76, 26(%rsp) #, MEM[(struct *)&u2 + 10B] movb $77, 27(%rsp) #, MEM[(struct *)&u2 + 11B] movb $-53, 28(%rsp) #, MEM[(struct *)&u2 + 12B] movb $60, 29(%rsp) #, MEM[(struct *)&u2 + 13B] movb $111, 30(%rsp) #, MEM[(struct *)&u2 + 14B] movb $53, 31(%rsp) #, MEM[(struct *)&u2 + 15B] call memcmp #So it is basically building that UUID byte by byte before calling memcmp.
And I'm wondering if those 16-byte arrays could be replaced with
typedef struct {
u64 a, b;
} u128;from the crypto code.
And whether the code generated by gcc would look much saner. Because the
CPU can handle two qwords much better/faster than 16 u8s.Anyway, in case someone feels bored...
--
Regards/Gruss,
Boris.SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers
Quoted 2 lines · Andy Shevchenko
Lukas pointed to this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68725
Yap, the same thing.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--