Skip to content

Commit 61b7302

Browse files
Ma KeNipaLocal
Ma Ke
authored and
NipaLocal
committed
net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
It could lead to error happen because the variable res is not updated if the call to sr_share_read_word returns an error. In this particular case error code was returned and res stayed uninitialized. Same issue also applies to sr_read_reg. This can be avoided by checking the return value of sr_share_read_word and sr_read_reg, and propagating the error if the read operation failed. Found by code review. Cc: stable@vger.kernel.org Fixes: c9b3745 ("USB2NET : SR9700 : One chip USB 1.1 USB2NET SR9700Device Driver Support") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Reviewed-by: Shigeru Yoshida <syoshida@redhat.com> Reviewed-by: Hariprasad Kelam <hkelam@marvell.com> Signed-off-by: NipaLocal <nipa@local>
1 parent 4167e6f commit 61b7302

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/net/usb/sr9700.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
179179
struct usbnet *dev = netdev_priv(netdev);
180180
__le16 res;
181181
int rc = 0;
182+
int err;
182183

183184
if (phy_id) {
184185
netdev_dbg(netdev, "Only internal phy supported\n");
@@ -189,11 +190,17 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
189190
if (loc == MII_BMSR) {
190191
u8 value;
191192

192-
sr_read_reg(dev, SR_NSR, &value);
193+
err = sr_read_reg(dev, SR_NSR, &value);
194+
if (err < 0)
195+
return err;
196+
193197
if (value & NSR_LINKST)
194198
rc = 1;
195199
}
196-
sr_share_read_word(dev, 1, loc, &res);
200+
err = sr_share_read_word(dev, 1, loc, &res);
201+
if (err < 0)
202+
return err;
203+
197204
if (rc == 1)
198205
res = le16_to_cpu(res) | BMSR_LSTATUS;
199206
else

0 commit comments

Comments
 (0)