Skip to content

Commit

Permalink
net: dp83640: reinforce locking rules.
Browse files Browse the repository at this point in the history
Callers of the ext_write function are supposed to hold a mutex that
protects the state of the dialed page, but one caller was missing the
lock from the very start, and over time the code has been changed
without following the rule.  This patch cleans up the call sites in
violation of the rule.

Signed-off-by: Richard Cochran <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
richardcochran authored and davem330 committed May 25, 2015
1 parent 397a253 commit a935865
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/net/phy/dp83640.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
else
evnt |= EVNT_RISE;
}
mutex_lock(&clock->extreg_lock);
ext_write(0, phydev, PAGE5, PTP_EVNT, evnt);
mutex_unlock(&clock->extreg_lock);
return 0;

case PTP_CLK_REQ_PEROUT:
Expand Down Expand Up @@ -532,16 +534,22 @@ static u8 status_frame_src[6] = { 0x08, 0x00, 0x17, 0x0B, 0x6B, 0x0F };

static void enable_status_frames(struct phy_device *phydev, bool on)
{
struct dp83640_private *dp83640 = phydev->priv;
struct dp83640_clock *clock = dp83640->clock;
u16 cfg0 = 0, ver;

if (on)
cfg0 = PSF_EVNT_EN | PSF_RXTS_EN | PSF_TXTS_EN | ENDIAN_FLAG;

ver = (PSF_PTPVER & VERSIONPTP_MASK) << VERSIONPTP_SHIFT;

mutex_lock(&clock->extreg_lock);

ext_write(0, phydev, PAGE5, PSF_CFG0, cfg0);
ext_write(0, phydev, PAGE6, PSF_CFG1, ver);

mutex_unlock(&clock->extreg_lock);

if (!phydev->attached_dev) {
pr_warn("expected to find an attached netdevice\n");
return;
Expand Down Expand Up @@ -1173,11 +1181,18 @@ static int dp83640_config_init(struct phy_device *phydev)

if (clock->chosen && !list_empty(&clock->phylist))
recalibrate(clock);
else
else {
mutex_lock(&clock->extreg_lock);
enable_broadcast(phydev, clock->page, 1);
mutex_unlock(&clock->extreg_lock);
}

enable_status_frames(phydev, true);

mutex_lock(&clock->extreg_lock);
ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE);
mutex_unlock(&clock->extreg_lock);

return 0;
}

Expand Down

0 comments on commit a935865

Please sign in to comment.