Commit b553a0fd authored by Alessandro Rubini's avatar Alessandro Rubini

bmc: use an idcmp() helper to simplify expressions

This replaces
     memcmp(a, b, PP_CLOCK_IDENTITY_LENGTH)
with
     idcmp(a, b)
and makes no other changes.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 44d3922f
...@@ -88,6 +88,10 @@ static void copy_d0(struct pp_instance *ppi, struct pp_frgn_master *m) ...@@ -88,6 +88,10 @@ static void copy_d0(struct pp_instance *ppi, struct pp_frgn_master *m)
hdr->sourcePortIdentity.clockIdentity = defds->clockIdentity; hdr->sourcePortIdentity.clockIdentity = defds->clockIdentity;
} }
static int idcmp(struct ClockIdentity *a, struct ClockIdentity *b)
{
return memcmp(a, b, sizeof(*a));
}
/* /*
* Data set comparison between two foreign masters (9.3.4 fig 27) * Data set comparison between two foreign masters (9.3.4 fig 27)
...@@ -107,8 +111,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -107,8 +111,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
PP_VPRINTF("BMC: in bmc_dataset_cmp\n"); PP_VPRINTF("BMC: in bmc_dataset_cmp\n");
/* Identity comparison */ /* Identity comparison */
if (!memcmp(&aa->grandmasterIdentity, if (!idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity)) {
&ab->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH)) {
/* Algorithm part2 Fig 28 */ /* Algorithm part2 Fig 28 */
if (aa->stepsRemoved > ab->stepsRemoved + 1) if (aa->stepsRemoved > ab->stepsRemoved + 1)
...@@ -120,8 +123,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -120,8 +123,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
ppci = &DSPAR(ppi)->parentPortIdentity.clockIdentity; ppci = &DSPAR(ppi)->parentPortIdentity.clockIdentity;
if (aa->stepsRemoved > ab->stepsRemoved) { if (aa->stepsRemoved > ab->stepsRemoved) {
if (!memcmp(&ha->sourcePortIdentity.clockIdentity, if (!idcmp(&ha->sourcePortIdentity.clockIdentity, ppci)) {
ppci, PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -1"); PP_PRINTF("Sender=Receiver: Error -1");
return 0; return 0;
} }
...@@ -129,25 +131,20 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -129,25 +131,20 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
} }
if (ab->stepsRemoved > aa->stepsRemoved) { if (ab->stepsRemoved > aa->stepsRemoved) {
if (!memcmp(&hb->sourcePortIdentity.clockIdentity, if (!idcmp(&hb->sourcePortIdentity.clockIdentity, ppci)) {
ppci, PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -3"); PP_PRINTF("Sender=Receiver: Error -3");
return 0; return 0;
} }
return -1; return -1;
} }
if (!memcmp( if (!idcmp(&ha->sourcePortIdentity.clockIdentity,
&ha->sourcePortIdentity.clockIdentity, &hb->sourcePortIdentity.clockIdentity)) {
&hb->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -2"); PP_PRINTF("Sender=Receiver: Error -2");
return 0; return 0;
} }
if ((memcmp( if (idcmp(&ha->sourcePortIdentity.clockIdentity,
&ha->sourcePortIdentity.clockIdentity, &hb->sourcePortIdentity.clockIdentity) < 0)
&hb->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) < 0)
return -1; return -1;
return 1; return 1;
} }
...@@ -171,8 +168,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -171,8 +168,7 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
if (aa->grandmasterPriority2 != ab->grandmasterPriority2) if (aa->grandmasterPriority2 != ab->grandmasterPriority2)
return aa->grandmasterPriority2 - ab->grandmasterPriority2; return aa->grandmasterPriority2 - ab->grandmasterPriority2;
return memcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity, return idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity);
PP_CLOCK_IDENTITY_LENGTH);
} }
/* State decision algorithm 9.3.3 Fig 26 */ /* State decision algorithm 9.3.3 Fig 26 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment