Skip to content

Commit

Permalink
uds: take the interface data off the stack.
Browse files Browse the repository at this point in the history
The 'struct interface' for the UDS port is allocated on the stack, and
when this gets passed to port_open, the port instance takes a pointer to
the string in the 'name' field. Currently this is harmless for the UDS
port, but it is not good form. This patch fixes the issue by making the
interface part of the clock instance.

Signed-off-by: Richard Cochran <[email protected]>
Reported-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
richardcochran committed Jan 8, 2014
1 parent 5dd5af5 commit 21889c5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct clock {
struct clock_stats stats;
int stats_interval;
struct clockcheck *sanity_check;
struct interface uds_interface;
};

struct clock the_clock;
Expand Down Expand Up @@ -577,20 +578,19 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
int i, fadj = 0, max_adj = 0.0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
struct clock *c = &the_clock;
char phc[32];
struct interface udsif;
struct interface *udsif = &c->uds_interface;
struct timespec ts;

memset(&udsif, 0, sizeof(udsif));
snprintf(udsif.name, sizeof(udsif.name), "%s", uds_path);
udsif.transport = TRANS_UDS;
udsif.delay_filter_length = 1;

clock_gettime(CLOCK_REALTIME, &ts);
srandom(ts.tv_sec ^ ts.tv_nsec);

if (c->nports)
clock_destroy(c);

snprintf(udsif->name, sizeof(udsif->name), "%s", uds_path);
udsif->transport = TRANS_UDS;
udsif->delay_filter_length = 1;

c->free_running = dds->free_running;
c->freq_est_interval = dds->freq_est_interval;
c->grand_master_capable = dds->grand_master_capable;
Expand Down Expand Up @@ -696,7 +696,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
/*
* One extra port is for the UDS interface.
*/
c->port[i] = port_open(phc_index, timestamping, 0, &udsif, c);
c->port[i] = port_open(phc_index, timestamping, 0, udsif, c);
if (!c->port[i]) {
pr_err("failed to open the UDS port");
return NULL;
Expand Down

0 comments on commit 21889c5

Please sign in to comment.