clock: Add NULL check for best clock in clock_update_slave()

This scenario will only be encountered when the clock transitions to the
slave state without knowing who the master is.

This will result in a segfault for BMCA with designated master and slave
states (to be added in upcoming patches).

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
master
Vedang Patel 2018-10-03 09:41:48 -07:00 committed by Richard Cochran
parent 4910055bd7
commit 386fc3ed89
1 changed files with 6 additions and 1 deletions

View File

@ -636,7 +636,12 @@ static void clock_update_grandmaster(struct clock *c)
static void clock_update_slave(struct clock *c) static void clock_update_slave(struct clock *c)
{ {
struct parentDS *pds = &c->dad.pds; struct parentDS *pds = &c->dad.pds;
struct ptp_message *msg = TAILQ_FIRST(&c->best->messages); struct ptp_message *msg;
if (!c->best)
return;
msg = TAILQ_FIRST(&c->best->messages);
c->cur.stepsRemoved = 1 + c->best->dataset.stepsRemoved; c->cur.stepsRemoved = 1 + c->best->dataset.stepsRemoved;
pds->parentPortIdentity = c->best->dataset.sender; pds->parentPortIdentity = c->best->dataset.sender;
pds->grandmasterIdentity = msg->announce.grandmasterIdentity; pds->grandmasterIdentity = msg->announce.grandmasterIdentity;