Skip to content

Commit f162b9d

Browse files
Andy FlemingJeff Garzik
authored andcommitted
gianfar: Fix a locking bug in gianfar's sysfs code
During sparse cleanup, found a locking bug. Some of the sysfs functions were acquiring a lock, and then returning in the event of an error. We rearrange the code so that the lock is released in error conditions, too. Signed-off-by: Andy Fleming <afleming@freescale.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
1 parent 569f0c4 commit f162b9d

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎drivers/net/gianfar.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static int gfar_poll(struct napi_struct *napi, int budget);
138138
static void gfar_netpoll(struct net_device *dev);
139139
#endif
140140
int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
141+
static int gfar_clean_tx_ring(struct net_device *dev);
141142
static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
142143
static void gfar_vlan_rx_register(struct net_device *netdev,
143144
struct vlan_group *grp);
@@ -1141,7 +1142,7 @@ static int gfar_close(struct net_device *dev)
11411142
}
11421143

11431144
/* Changes the mac address if the controller is not running. */
1144-
int gfar_set_mac_address(struct net_device *dev)
1145+
static int gfar_set_mac_address(struct net_device *dev)
11451146
{
11461147
gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
11471148

@@ -1260,7 +1261,7 @@ static void gfar_timeout(struct net_device *dev)
12601261
}
12611262

12621263
/* Interrupt Handler for Transmit complete */
1263-
int gfar_clean_tx_ring(struct net_device *dev)
1264+
static int gfar_clean_tx_ring(struct net_device *dev)
12641265
{
12651266
struct txbd8 *bdp;
12661267
struct gfar_private *priv = netdev_priv(dev);

‎drivers/net/gianfar.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,5 +782,8 @@ extern void gfar_halt(struct net_device *dev);
782782
extern void gfar_phy_test(struct mii_bus *bus, struct phy_device *phydev,
783783
int enable, u32 regnum, u32 read);
784784
void gfar_init_sysfs(struct net_device *dev);
785+
int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id,
786+
int regnum, u16 value);
787+
int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum);
785788

786789
#endif /* __GIANFAR_H */

‎drivers/net/gianfar_sysfs.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ static ssize_t gfar_set_rx_stash_size(struct device *dev,
103103

104104
spin_lock_irqsave(&priv->rxlock, flags);
105105
if (length > priv->rx_buffer_size)
106-
return count;
106+
goto out;
107107

108108
if (length == priv->rx_stash_size)
109-
return count;
109+
goto out;
110110

111111
priv->rx_stash_size = length;
112112

@@ -125,6 +125,7 @@ static ssize_t gfar_set_rx_stash_size(struct device *dev,
125125

126126
gfar_write(&priv->regs->attr, temp);
127127

128+
out:
128129
spin_unlock_irqrestore(&priv->rxlock, flags);
129130

130131
return count;
@@ -154,10 +155,10 @@ static ssize_t gfar_set_rx_stash_index(struct device *dev,
154155

155156
spin_lock_irqsave(&priv->rxlock, flags);
156157
if (index > priv->rx_stash_size)
157-
return count;
158+
goto out;
158159

159160
if (index == priv->rx_stash_index)
160-
return count;
161+
goto out;
161162

162163
priv->rx_stash_index = index;
163164

@@ -166,6 +167,7 @@ static ssize_t gfar_set_rx_stash_index(struct device *dev,
166167
temp |= ATTRELI_EI(index);
167168
gfar_write(&priv->regs->attreli, flags);
168169

170+
out:
169171
spin_unlock_irqrestore(&priv->rxlock, flags);
170172

171173
return count;

0 commit comments

Comments
 (0)