2017-04-21 17:02:53

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 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.

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(+)

diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 4dff73a89758..45312cb5ac65 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -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);
--
2.11.0


2017-04-21 14:50:24

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers

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(-)

diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c
index 502ea4dc2080..45e299aefda7 100644
--- a/drivers/acpi/acpi_extlog.c
+++ b/drivers/acpi/acpi_extlog.c
@@ -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,
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index d0855c09f32f..f2a7ee26d45f 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -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 &&
--
2.11.0

2017-04-21 14:49:44

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 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.

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(-)

diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c
index 600faad19bd4..4bf171985872 100644
--- a/sound/soc/intel/skylake/skl-pcm.c
+++ b/sound/soc/intel/skylake/skl-pcm.c
@@ -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;
diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
index 6d5bff04bf65..67288580c743 100644
--- a/sound/soc/intel/skylake/skl-sst-utils.c
+++ b/sound/soc/intel/skylake/skl-sst-utils.c
@@ -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;
--
2.11.0

2017-04-21 14:50:59

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 4/8] vfio-mdev: 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.

Cc: Kirti Wankhede <[email protected]>
Cc: Alex Williamson <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/vfio/mdev/mdev_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 126991046eb7..82de886855d8 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -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;
--
2.11.0

2017-04-21 17:03:10

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 5/8] vmbus: Use recently introduced uuid_le_cmp_p{p}() helpers

Recently introduced helpers take pointers to uuid_{be|le} instead of
reference.

Using them makes code less ugly.

Cc: "K. Y. Srinivasan" <[email protected]>
Cc: Haiyang Zhang <[email protected]>
Cc: Stephen Hemminger <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/hv/channel_mgmt.c | 10 +++++-----
drivers/hv/vmbus_drv.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 735f9363f2e4..01570c50ed04 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -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;
}
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 0087b49095eb..b41a2be778f6 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -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;
}
--
2.11.0

2017-04-21 17:03:11

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 7/8] efi: Use recently introduced uuid_le_cmp_p{p}() helpers

Recently introduced helpers take pointers to uuid_{be|le} instead of
reference.

Using them makes code less ugly.

Cc: Matt Fleming <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/firmware/efi/cper.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index d42537425438..7735b0f0ea90 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -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))
--
2.11.0

2017-04-21 18:49:11

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 6/8] mei: Use recently introduced uuid_le_cmp_p{p}() helpers

Recently introduced helpers take pointers to uuid_{be|le} instead of
reference.

Using them makes code less ugly.

Cc: Tomas Winkler <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
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(-)

diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index 0208c4b027c5..de0fcd98d162 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -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);
}
}
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index d1928fdd0f43..e15549f71891 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -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])
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index be64969d986a..590accb369bd 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -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);
}
--
2.11.0

2017-04-21 19:18:59

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 3/8] HID: intel_ish-hid: 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.

Cc: Srinivas Pandruvada <[email protected]>
Cc: Benjamin Tissoires <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/hid/intel-ish-hid/ishtp/bus.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c
index 5f382fedc2ab..165e21b7ee9f 100644
--- a/drivers/hid/intel-ish-hid/ishtp/bus.c
+++ b/drivers/hid/intel-ish-hid/ishtp/bus.c
@@ -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;
}
--
2.11.0

2017-04-21 21:28:45

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers

On Friday, April 21, 2017 05:46:45 PM Andy Shevchenko wrote:
> 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(-)
>
> diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c
> index 502ea4dc2080..45e299aefda7 100644
> --- a/drivers/acpi/acpi_extlog.c
> +++ b/drivers/acpi/acpi_extlog.c
> @@ -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.

> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
> index d0855c09f32f..f2a7ee26d45f 100644
> --- a/drivers/acpi/apei/ghes.c
> +++ b/drivers/acpi/apei/ghes.c
> @@ -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 &&
>

But this one is for Boris.

Thanks,
Rafael

2017-04-23 10:29:27

by Tomas Winkler

[permalink] [raw]
Subject: RE: [PATCH v1 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.
>
> 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(+)
>
> diff --git a/include/linux/uuid.h b/include/linux/uuid.h index
> 4dff73a89758..45312cb5ac65 100644
> --- a/include/linux/uuid.h
> +++ b/include/linux/uuid.h
> @@ -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);

I think this going overboard, the _pp types are just enough.
Tomas

2017-04-23 12:42:48

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 1/8] lib/uuid: Introduce uuid_{be|le}_cmp_p{p}() helpers

On Sun, Apr 23, 2017 at 1:29 PM, Winkler, Tomas <[email protected]> wrote:
>> 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 _pp types 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.

--
With Best Regards,
Andy Shevchenko

2017-04-23 20:20:49

by Tomas Winkler

[permalink] [raw]
Subject: Re: [PATCH v1 1/8] lib/uuid: Introduce uuid_{be|le}_cmp_p{p}() helpers

On Sun, 2017-04-23 at 15:42 +0300, Andy Shevchenko wrote:
> On Sun, Apr 23, 2017 at 1:29 PM, Winkler, Tomas <tomas.winkler@intel.
> com> wrote:
> > > 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 _pp types  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.


Maybe it's worth to actually replace the defines with variables than to
create an interface with all the permutations.

Tomas

2017-04-24 04:49:28

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH v1 2/8] ASoC: Intel: Skylake: Use recently introduced uuid_le_cmp_p{p}()

On Fri, Apr 21, 2017 at 05:46:39PM +0300, Andy Shevchenko wrote:
> 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

>
> Using them makes code less ugly.

How so..?

>
> 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(-)
>
> diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c
> index 600faad19bd4..4bf171985872 100644
> --- a/sound/soc/intel/skylake/skl-pcm.c
> +++ b/sound/soc/intel/skylake/skl-pcm.c
> @@ -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;
> diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
> index 6d5bff04bf65..67288580c743 100644
> --- a/sound/soc/intel/skylake/skl-sst-utils.c
> +++ b/sound/soc/intel/skylake/skl-sst-utils.c
> @@ -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;
> --
> 2.11.0
>

--
~Vinod

2017-04-24 08:54:15

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/8] ASoC: Intel: Skylake: Use recently introduced uuid_le_cmp_p{p}()

On Mon, 2017-04-24 at 10:21 +0530, Vinod Koul wrote:
> On Fri, Apr 21, 2017 at 05:46:39PM +0300, Andy Shevchenko wrote:
> > 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.

> >
> > 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).

>
> >
> > 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(-)
> >
> > diff --git a/sound/soc/intel/skylake/skl-pcm.c
> > b/sound/soc/intel/skylake/skl-pcm.c
> > index 600faad19bd4..4bf171985872 100644
> > --- a/sound/soc/intel/skylake/skl-pcm.c
> > +++ b/sound/soc/intel/skylake/skl-pcm.c
> > @@ -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;
> > diff --git a/sound/soc/intel/skylake/skl-sst-utils.c
> > b/sound/soc/intel/skylake/skl-sst-utils.c
> > index 6d5bff04bf65..67288580c743 100644
> > --- a/sound/soc/intel/skylake/skl-sst-utils.c
> > +++ b/sound/soc/intel/skylake/skl-sst-utils.c
> > @@ -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;
> > -- 
> > 2.11.0
> >
>
>

--
Andy Shevchenko <[email protected]>
Intel Finland Oy

2017-04-24 08:55:46

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 1/8] lib/uuid: Introduce uuid_{be|le}_cmp_p{p}() helpers

On Sun, 2017-04-23 at 20:20 +0000, Winkler, Tomas wrote:
> On Sun, 2017-04-23 at 15:42 +0300, Andy Shevchenko wrote:
> > On Sun, Apr 23, 2017 at 1:29 PM, Winkler, Tomas <tomas.winkler@intel
> > .
> > com> wrote:
> > > > 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 _pp types  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.
>
>
> 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.

--
Andy Shevchenko <[email protected]>
Intel Finland Oy

2017-04-24 10:43:48

by Lukas Wunner

[permalink] [raw]
Subject: Re: [PATCH v1 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.
>
> 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(+)
>
> diff --git a/include/linux/uuid.h b/include/linux/uuid.h index
> 4dff73a89758..45312cb5ac65 100644
> --- a/include/linux/uuid.h
> +++ b/include/linux/uuid.h
> @@ -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);

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

2017-04-27 12:46:57

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers

On Fri, Apr 21, 2017 at 11:22:31PM +0200, Rafael J. Wysocki wrote:
> > #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.

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...

--
Regards/Gruss,
Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--

2017-04-27 13:10:10

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers

On Thu, 2017-04-27 at 14:46 +0200, Borislav Petkov wrote:
> On Fri, Apr 21, 2017 at 11:22:31PM +0200, Rafael J. Wysocki wrote:
> > >  #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.
>
> 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

>
> 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)

--
Andy Shevchenko <[email protected]>
Intel Finland Oy

2017-04-27 15:00:47

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH v1 8/8] ACPI: Use recently introduced uuid_le_cmp_p{p}() helpers

On Thu, Apr 27, 2017 at 04:09:56PM +0300, Andy Shevchenko wrote:
> Lukas pointed to this:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68725

Yap, the same thing.

Thanks.

--
Regards/Gruss,
Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--