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,11 +108,9 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -108,11 +108,9 @@ 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 (ann_a->stepsRemoved > ann_b->stepsRemoved) {
...@@ -122,37 +120,37 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -122,37 +120,37 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
PP_CLOCK_IDENTITY_LENGTH)) { PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -1"); PP_PRINTF("Sender=Receiver: Error -1");
return 0; return 0;
} else }
return 1; return 1;
} else if (ann_b->stepsRemoved > ann_a->stepsRemoved) { }
if (ann_b->stepsRemoved > ann_a->stepsRemoved) {
if (!memcmp( if (!memcmp(
&hdr_b->sourcePortIdentity.clockIdentity, &hdr_b->sourcePortIdentity.clockIdentity,
ppci, ppci,
PP_CLOCK_IDENTITY_LENGTH)) { PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -3"); PP_PRINTF("Sender=Receiver: Error -3");
return 0; return 0;
} else { }
return -1; return -1;
} }
} else { /* steps removed A == steps removed B */
if (!memcmp( if (!memcmp(
&hdr_a->sourcePortIdentity.clockIdentity, &hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity, &hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) { PP_CLOCK_IDENTITY_LENGTH)) {
PP_PRINTF("Sender=Receiver: Error -2"); PP_PRINTF("Sender=Receiver: Error -2");
return 0; return 0;
} else if ((memcmp( }
if ((memcmp(
&hdr_a->sourcePortIdentity.clockIdentity, &hdr_a->sourcePortIdentity.clockIdentity,
&hdr_b->sourcePortIdentity.clockIdentity, &hdr_b->sourcePortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) < 0) PP_CLOCK_IDENTITY_LENGTH)) < 0)
return -1; return -1;
else
return 1; return 1;
} }
}
} else { /* GrandMaster are not identical */ /* GrandMaster are not identical */
/* FIXME: rewrite in a more readable way */
if (ann_a->grandmasterPriority1 == ann_b->grandmasterPriority1) { if (ann_a->grandmasterPriority1 == ann_b->grandmasterPriority1) {
if (ann_a->grandmasterClockQuality.clockClass == if (ann_a->grandmasterClockQuality.clockClass ==
ann_b->grandmasterClockQuality.clockClass) { ann_b->grandmasterClockQuality.clockClass) {
...@@ -162,59 +160,49 @@ static int bmc_dataset_cmp(struct pp_instance *ppi, ...@@ -162,59 +160,49 @@ static int bmc_dataset_cmp(struct pp_instance *ppi,
comp = memcmp(&ann_a->grandmasterIdentity, &ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH); comp = memcmp(&ann_a->grandmasterIdentity, &ann_b->grandmasterIdentity, PP_CLOCK_IDENTITY_LENGTH);
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 { }
/* Priority2 are not identical */ /* Priority2 are not identical */
comp = memcmp(&ann_a->grandmasterPriority2, &ann_b->grandmasterPriority2, 1); comp = memcmp(&ann_a->grandmasterPriority2, &ann_b->grandmasterPriority2, 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 {
/* offsetScaledLogVariance 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;
} }
/* Accuracy are not identitcal */
} else { /* Accuracy are not identitcal */
comp = memcmp(&ann_a->grandmasterClockQuality.clockAccuracy, &ann_b->grandmasterClockQuality.clockAccuracy, 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 */ /* ClockClass 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 */ /* Priority1 are not identical */
comp = memcmp(&ann_a->grandmasterPriority1, &ann_b->grandmasterPriority1, 1); comp = memcmp(&ann_a->grandmasterPriority1, &ann_b->grandmasterPriority1, 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;
}
}
} }
/* 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) { }
if (cmpres > 0) {
s1(ppi, hdr, ann); s1(ppi, hdr, ann);
return PPS_PASSIVE; return PPS_PASSIVE;
} }
}
} else {
if (cmpres < 0) { if (cmpres < 0) {
m1(ppi); m1(ppi);
return PPS_MASTER; return PPS_MASTER;
} else if (cmpres > 0) { }
if (cmpres > 0) {
s1(ppi, hdr, ann); s1(ppi, hdr, ann);
return PPS_SLAVE; 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