Commit ca0eb70f authored by Alessandro Rubini's avatar Alessandro Rubini

bmc: remove needless else statements

When the "if" branch returns, we don't need an "else" branch.  These
students wouldn't pass my exam.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 291a1e1e
...@@ -108,113 +108,101 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -108,113 +108,101 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
if (ann_a->stepsRemoved > ann_b->stepsRemoved + 1) if (ann_a->stepsRemoved > ann_b->stepsRemoved + 1)
return 1; return 1;
else if (ann_b->stepsRemoved > ann_a->stepsRemoved + 1) if (ann_b->stepsRemoved > ann_a->stepsRemoved + 1)
return -1; return -1;
else { /* A within 1 of B */ ppci = DSPAR(ppi)->parentPortIdentity.clockIdentity.id;
ppci = DSPAR(ppi)->parentPortIdentity.clockIdentity.id; if (ann_a->stepsRemoved > ann_b->stepsRemoved) {
if (!memcmp(
if (ann_a->stepsRemoved > ann_b->stepsRemoved) { &hdr_a->sourcePortIdentity.clockIdentity,
if (!memcmp( ppci,
&hdr_a->sourcePortIdentity.clockIdentity, PP_CLOCK_IDENTITY_LENGTH)) {
ppci, PP_PRINTF("Sender=Receiver: Error -1");
PP_CLOCK_IDENTITY_LENGTH)) { return 0;
PP_PRINTF("Sender=Receiver: Error -1"); }
return 0; return 1;
} else
return 1;
} else if (ann_b->stepsRemoved > ann_a->stepsRemoved) { }
if (!memcmp( if (ann_b->stepsRemoved > ann_a->stepsRemoved) {
&hdr_b->sourcePortIdentity.clockIdentity, if (!memcmp(
ppci, &hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) { ppci,
PP_PRINTF("Sender=Receiver: Error -3"); PP_CLOCK_IDENTITY_LENGTH)) {
return 0; PP_PRINTF("Sender=Receiver: Error -3");
} else { return 0;
return -1;
}
} else { /* steps removed A == steps removed B */
if (!memcmp(
&hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -2");
return 0;
} else if ((memcmp(
&hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) < 0)
return -1;
else
return 1;
} }
return -1;
}
if (!memcmp(
&hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -2");
return 0;
} }
} else { /* GrandMaster are not identical */ if ((memcmp(
/* FIXME: rewrite in a more readable way */ &hdr_a->sourcePortIdentity.clockIdentity,
if (ann_a->grandmasterPriority1 == ann_b->grandmasterPriority1) { &hdr_b->sourcePortIdentity.clockIdentity,
if (ann_a->grandmasterClockQuality.clockClass == PP_CLOCK_IDENTITY_LENGTH)) < 0)
ann_b->grandmasterClockQuality.clockClass) { return -1;
if (ann_a->grandmasterClockQuality.clockAccuracy == ann_b->grandmasterClockQuality.clockAccuracy) { return 1;
if (ann_a->grandmasterClockQuality.offsetScaledLogVariance == ann_b->grandmasterClockQuality.offsetScaledLogVariance) { }
if (ann_a->grandmasterPriority2 == ann_b->grandmasterPriority2) {
comp = memcmp(&ann_a->grandmasterIdentity, &ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH); /* GrandMaster are not identical */
if (comp < 0) if (ann_a->grandmasterPriority1 == ann_b->grandmasterPriority1) {
return -1; if (ann_a->grandmasterClockQuality.clockClass ==
else if (comp > 0) ann_b->grandmasterClockQuality.clockClass) {
return 1; if (ann_a->grandmasterClockQuality.clockAccuracy == ann_b->grandmasterClockQuality.clockAccuracy) {
else if (ann_a->grandmasterClockQuality.offsetScaledLogVariance == ann_b->grandmasterClockQuality.offsetScaledLogVariance) {
return 0; if (ann_a->grandmasterPriority2 == ann_b->grandmasterPriority2) {
} else { comp = memcmp(&ann_a->grandmasterIdentity, &ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
/* Priority2 are not identical */
comp = memcmp(&ann_a->grandmasterPriority2, &ann_b->grandmasterPriority2, 1);
if (comp < 0)
return -1;
else if (comp > 0)
return 1;
else
return 0;
}
} else {
/* offsetScaledLogVariance are not identical */
comp = memcmp(&ann_a->grandmasterClockQuality.clockClass, &ann_b->grandmasterClockQuality.clockClass, 1);
if (comp < 0) if (comp < 0)
return -1; return -1;
else if (comp > 0) if (comp > 0)
return 1; return 1;
else return 0;
return 0;
} }
/* Priority2 are not identical */
} else { /* Accuracy are not identitcal */ comp = memcmp(&ann_a->grandmasterPriority2, &ann_b->grandmasterPriority2, 1);
comp = memcmp(&ann_a->grandmasterClockQuality.clockAccuracy, &ann_b->grandmasterClockQuality.clockAccuracy, 1);
if (comp < 0) if (comp < 0)
return -1; return -1;
else if (comp > 0) if (comp > 0)
return 1; return 1;
else return 0;
return 0;
} }
} else { /* ClockClass are not identical */ /* offsetScaledLogVariance are not identical */
comp = memcmp(&ann_a->grandmasterClockQuality.clockClass, &ann_b->grandmasterClockQuality.clockClass, 1); comp = memcmp(&ann_a->grandmasterClockQuality.clockClass, &ann_b->grandmasterClockQuality.clockClass, 1);
if (comp < 0) if (comp < 0)
return -1; return -1;
else if (comp > 0) if (comp > 0)
return 1; return 1;
else return 0;
return 0;
} }
} else { /* Priority1 are not identical */ /* Accuracy are not identitcal */
comp = memcmp(&ann_a->grandmasterPriority1, &ann_b->grandmasterPriority1, 1); comp = memcmp(&ann_a->grandmasterClockQuality.clockAccuracy, &ann_b->grandmasterClockQuality.clockAccuracy, 1);
if (comp < 0) if (comp < 0)
return -1; return -1;
else if (comp > 0) if (comp > 0)
return 1; return 1;
else return 0;
return 0;
} }
/* ClockClass are not identical */
comp = memcmp(&ann_a->grandmasterClockQuality.clockClass, &ann_b->grandmasterClockQuality.clockClass, 1);
if (comp < 0)
return -1;
if (comp > 0)
return 1;
return 0;
} }
/* Priority1 are not identical */
comp = memcmp(&ann_a->grandmasterPriority1, &ann_b->grandmasterPriority1, 1);
if (comp < 0)
return -1;
if (comp > 0)
return 1;
return 0;
} }
/* State decision algorithm 9.3.3 Fig 26 */ /* State decision algorithm 9.3.3 Fig 26 */
...@@ -248,20 +236,20 @@ UInteger8 bmc_state_decision(struct pp_instance *ppi, ...@@ -248,20 +236,20 @@ UInteger8 bmc_state_decision(struct pp_instance *ppi,
if (cmpres < 0) { if (cmpres < 0) {
m1(ppi); m1(ppi);
return PPS_MASTER; return PPS_MASTER;
} else if (cmpres > 0) {
s1(ppi, hdr, ann);
return PPS_PASSIVE;
} }
if (cmpres > 0) {
} else {
if (cmpres < 0) {
m1(ppi);
return PPS_MASTER;
} else if (cmpres > 0) {
s1(ppi, hdr, ann); s1(ppi, hdr, ann);
return PPS_SLAVE; return PPS_PASSIVE;
} }
} }
if (cmpres < 0) {
m1(ppi);
return PPS_MASTER;
}
if (cmpres > 0) {
s1(ppi, hdr, ann);
return PPS_SLAVE;
}
if (cmpres == 0) if (cmpres == 0)
PP_PRINTF("Error in bmc_state_decision, cmpres=0.\n"); PP_PRINTF("Error in bmc_state_decision, cmpres=0.\n");
......
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