Skip to content

Commit

Permalink
mt76x02u: check chip version on probe
Browse files Browse the repository at this point in the history
Since some USB device IDs are duplicated between mt76x0u, mt7601u
and mt76x2u device, check chip version on probe and return error if
not match the driver.

Don't think this is serious issue, probe most likely will fail at
some other point for wrong device, but we do not have to configure
it if we know is not our device.

Reported-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  • Loading branch information
Stanislaw Gruszka authored and nbd168 committed Apr 25, 2019
1 parent b3a2965 commit ffddb68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mt76x0/usb.c
Expand Up @@ -232,7 +232,7 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
struct mt76x02_dev *dev;
struct mt76_dev *mdev;
u32 asic_rev, mac_rev;
u32 mac_rev;
int ret;

mdev = mt76_alloc_device(&usb_dev->dev, sizeof(*dev), &mt76x0u_ops,
Expand Down Expand Up @@ -265,10 +265,14 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
goto err;
}

asic_rev = mt76_rr(dev, MT_ASIC_VERSION);
mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
mac_rev = mt76_rr(dev, MT_MAC_CSR0);
dev_info(mdev->dev, "ASIC revision: %08x MAC revision: %08x\n",
asic_rev, mac_rev);
mdev->rev, mac_rev);
if (!is_mt76x0(dev)) {
ret = -ENODEV;
goto err;
}

/* Note: vendor driver skips this check for MT76X0U */
if (!(mt76_rr(dev, MT_EFUSE_CTRL) & MT_EFUSE_CTRL_SEL))
Expand Down
7 changes: 7 additions & 0 deletions mt76x02.h
Expand Up @@ -214,6 +214,13 @@ void mt76x02_mac_start(struct mt76x02_dev *dev);

void mt76x02_init_debugfs(struct mt76x02_dev *dev);

static inline bool is_mt76x0(struct mt76x02_dev *dev)
{
return mt76_chip(&dev->mt76) == 0x7610 ||
mt76_chip(&dev->mt76) == 0x7630 ||
mt76_chip(&dev->mt76) == 0x7650;
}

static inline bool is_mt76x2(struct mt76x02_dev *dev)
{
return mt76_chip(&dev->mt76) == 0x7612 ||
Expand Down
4 changes: 4 additions & 0 deletions mt76x2/usb.c
Expand Up @@ -69,6 +69,10 @@ static int mt76x2u_probe(struct usb_interface *intf,

mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);
if (!is_mt76x2(dev)) {
err = -ENODEV;
goto err;
}

err = mt76x2u_register_device(dev);
if (err < 0)
Expand Down

0 comments on commit ffddb68

Please sign in to comment.