drivers/net/wan/lmc/lmc_main.c:947 lmc_init_one() warn: 'dev' not released on lines: 903.

From: Dan Carpenter
Date: Mon Jul 05 2021 - 06:05:36 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a180bd1d7e16173d965b263c5a536aa40afa2a2a
commit: 62e69bc419772638369eff8ff81340bde8aceb61 net: wan/lmc: unregister device when no matching device is found
config: parisc-randconfig-m031-20210705 (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/net/wan/lmc/lmc_main.c:947 lmc_init_one() warn: 'dev' not released on lines: 903.

Old smatch warnings:
drivers/net/wan/lmc/lmc_main.c:721 lmc_watchdog() warn: inconsistent indenting
drivers/net/wan/lmc/lmc_main.c:867 lmc_init_one() warn: inconsistent indenting
drivers/net/wan/lmc/lmc_main.c:947 lmc_init_one() warn: 'pdev' not released on lines: 822,827,903.

vim +/dev +947 drivers/net/wan/lmc/lmc_main.c

1dd06ae8db716e Greg Kroah-Hartman 2012-12-06 796 static int lmc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
^1da177e4c3f41 Linus Torvalds 2005-04-16 797 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 798 lmc_softc_t *sc;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 799 struct net_device *dev;
^1da177e4c3f41 Linus Torvalds 2005-04-16 800 u16 subdevice;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 801 u16 AdapModelNum;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 802 int err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 803 static int cards_found;
^1da177e4c3f41 Linus Torvalds 2005-04-16 804
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 805 err = pcim_enable_device(pdev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 806 if (err) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 807 printk(KERN_ERR "lmc: pci enable failed: %d\n", err);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 808 return err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 809 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 810
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 811 err = pci_request_regions(pdev, "lmc");
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 812 if (err) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 813 printk(KERN_ERR "lmc: pci_request_region failed\n");
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 814 return err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 815 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 816
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 817 /*
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 818 * Allocate our own device structure
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 819 */
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 820 sc = devm_kzalloc(&pdev->dev, sizeof(lmc_softc_t), GFP_KERNEL);
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 821 if (!sc)
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 822 return -ENOMEM;

release regions and pcim_disable_device?

^1da177e4c3f41 Linus Torvalds 2005-04-16 823
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 824 dev = alloc_hdlcdev(sc);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 825 if (!dev) {
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 826 printk(KERN_ERR "lmc:alloc_netdev for device failed\n");
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 827 return -ENOMEM;
^1da177e4c3f41 Linus Torvalds 2005-04-16 828 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 829
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 830
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 831 dev->type = ARPHRD_HDLC;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 832 dev_to_hdlc(dev)->xmit = lmc_start_xmit;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 833 dev_to_hdlc(dev)->attach = lmc_attach;
991990a12de422 Krzysztof Hałasa 2009-01-08 834 dev->netdev_ops = &lmc_ops;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 835 dev->watchdog_timeo = HZ; /* 1 second */
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 836 dev->tx_queue_len = 100;
^1da177e4c3f41 Linus Torvalds 2005-04-16 837 sc->lmc_device = dev;
^1da177e4c3f41 Linus Torvalds 2005-04-16 838 sc->name = dev->name;
^1da177e4c3f41 Linus Torvalds 2005-04-16 839 sc->if_type = LMC_PPP;
^1da177e4c3f41 Linus Torvalds 2005-04-16 840 sc->check = 0xBEAFCAFE;
^1da177e4c3f41 Linus Torvalds 2005-04-16 841 dev->base_addr = pci_resource_start(pdev, 0);
^1da177e4c3f41 Linus Torvalds 2005-04-16 842 dev->irq = pdev->irq;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 843 pci_set_drvdata(pdev, dev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 844 SET_NETDEV_DEV(dev, &pdev->dev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 845
^1da177e4c3f41 Linus Torvalds 2005-04-16 846 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 847 * This will get the protocol layer ready and do any 1 time init's
^1da177e4c3f41 Linus Torvalds 2005-04-16 848 * Must have a valid sc and dev structure
^1da177e4c3f41 Linus Torvalds 2005-04-16 849 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 850 lmc_proto_attach(sc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 851
^1da177e4c3f41 Linus Torvalds 2005-04-16 852 /* Init the spin lock so can call it latter */
^1da177e4c3f41 Linus Torvalds 2005-04-16 853
^1da177e4c3f41 Linus Torvalds 2005-04-16 854 spin_lock_init(&sc->lmc_lock);
^1da177e4c3f41 Linus Torvalds 2005-04-16 855 pci_set_master(pdev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 856
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 857 printk(KERN_INFO "%s: detected at %lx, irq %d\n", dev->name,
^1da177e4c3f41 Linus Torvalds 2005-04-16 858 dev->base_addr, dev->irq);
^1da177e4c3f41 Linus Torvalds 2005-04-16 859
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 860 err = register_hdlc_device(dev);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 861 if (err) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 862 printk(KERN_ERR "%s: register_netdev failed.\n", dev->name);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 863 free_netdev(dev);
7cb43bebab52d8 Amitoj Kaur Chawla 2016-02-27 864 return err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 865 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 866
^1da177e4c3f41 Linus Torvalds 2005-04-16 867 sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;

Indenting uses spaces instead of tabs. Also wrong number of spaces.

^1da177e4c3f41 Linus Torvalds 2005-04-16 868 sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 869
^1da177e4c3f41 Linus Torvalds 2005-04-16 870 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 871 *
^1da177e4c3f41 Linus Torvalds 2005-04-16 872 * Check either the subvendor or the subdevice, some systems reverse
^1da177e4c3f41 Linus Torvalds 2005-04-16 873 * the setting in the bois, seems to be version and arch dependent?
^1da177e4c3f41 Linus Torvalds 2005-04-16 874 * Fix the error, exchange the two values
^1da177e4c3f41 Linus Torvalds 2005-04-16 875 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 876 if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
^1da177e4c3f41 Linus Torvalds 2005-04-16 877 subdevice = pdev->subsystem_vendor;
^1da177e4c3f41 Linus Torvalds 2005-04-16 878
^1da177e4c3f41 Linus Torvalds 2005-04-16 879 switch (subdevice) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 880 case PCI_DEVICE_ID_LMC_HSSI:
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 881 printk(KERN_INFO "%s: LMC HSSI\n", dev->name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 882 sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
^1da177e4c3f41 Linus Torvalds 2005-04-16 883 sc->lmc_media = &lmc_hssi_media;
^1da177e4c3f41 Linus Torvalds 2005-04-16 884 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 885 case PCI_DEVICE_ID_LMC_DS3:
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 886 printk(KERN_INFO "%s: LMC DS3\n", dev->name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 887 sc->lmc_cardtype = LMC_CARDTYPE_DS3;
^1da177e4c3f41 Linus Torvalds 2005-04-16 888 sc->lmc_media = &lmc_ds3_media;
^1da177e4c3f41 Linus Torvalds 2005-04-16 889 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 890 case PCI_DEVICE_ID_LMC_SSI:
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 891 printk(KERN_INFO "%s: LMC SSI\n", dev->name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 892 sc->lmc_cardtype = LMC_CARDTYPE_SSI;
^1da177e4c3f41 Linus Torvalds 2005-04-16 893 sc->lmc_media = &lmc_ssi_media;
^1da177e4c3f41 Linus Torvalds 2005-04-16 894 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 895 case PCI_DEVICE_ID_LMC_T1:
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 896 printk(KERN_INFO "%s: LMC T1\n", dev->name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 897 sc->lmc_cardtype = LMC_CARDTYPE_T1;
^1da177e4c3f41 Linus Torvalds 2005-04-16 898 sc->lmc_media = &lmc_t1_media;
^1da177e4c3f41 Linus Torvalds 2005-04-16 899 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 900 default:
af901ca181d92a André Goddard Rosa 2009-11-14 901 printk(KERN_WARNING "%s: LMC UNKNOWN CARD!\n", dev->name);
62e69bc4197726 Tong Zhang 2021-02-15 902 unregister_hdlc_device(dev);

More cleanup required? (I haven't looked at the unregister_hdlc_device()
function).

62e69bc4197726 Tong Zhang 2021-02-15 903 return -EIO;
^1da177e4c3f41 Linus Torvalds 2005-04-16 904 break;
^1da177e4c3f41 Linus Torvalds 2005-04-16 905 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 906
^1da177e4c3f41 Linus Torvalds 2005-04-16 907 lmc_initcsrs (sc, dev->base_addr, 8);
^1da177e4c3f41 Linus Torvalds 2005-04-16 908
^1da177e4c3f41 Linus Torvalds 2005-04-16 909 lmc_gpio_mkinput (sc, 0xff);
^1da177e4c3f41 Linus Torvalds 2005-04-16 910 sc->lmc_gpio = 0; /* drive no signals yet */
^1da177e4c3f41 Linus Torvalds 2005-04-16 911
^1da177e4c3f41 Linus Torvalds 2005-04-16 912 sc->lmc_media->defaults (sc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 913
^1da177e4c3f41 Linus Torvalds 2005-04-16 914 sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
^1da177e4c3f41 Linus Torvalds 2005-04-16 915
^1da177e4c3f41 Linus Torvalds 2005-04-16 916 /* verify that the PCI Sub System ID matches the Adapter Model number
^1da177e4c3f41 Linus Torvalds 2005-04-16 917 * from the MII register
^1da177e4c3f41 Linus Torvalds 2005-04-16 918 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 919 AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
^1da177e4c3f41 Linus Torvalds 2005-04-16 920
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 921 if ((AdapModelNum != LMC_ADAP_T1 || /* detect LMC1200 */
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 922 subdevice != PCI_DEVICE_ID_LMC_T1) &&
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 923 (AdapModelNum != LMC_ADAP_SSI || /* detect LMC1000 */
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 924 subdevice != PCI_DEVICE_ID_LMC_SSI) &&
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 925 (AdapModelNum != LMC_ADAP_DS3 || /* detect LMC5245 */
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 926 subdevice != PCI_DEVICE_ID_LMC_DS3) &&
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 927 (AdapModelNum != LMC_ADAP_HSSI || /* detect LMC5200 */
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 928 subdevice != PCI_DEVICE_ID_LMC_HSSI))
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 929 printk(KERN_WARNING "%s: Model number (%d) miscompare for PCI"
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 930 " Subsystem ID = 0x%04x\n",
^1da177e4c3f41 Linus Torvalds 2005-04-16 931 dev->name, AdapModelNum, subdevice);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 932
^1da177e4c3f41 Linus Torvalds 2005-04-16 933 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 934 * reset clock
^1da177e4c3f41 Linus Torvalds 2005-04-16 935 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 936 LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
^1da177e4c3f41 Linus Torvalds 2005-04-16 937
^1da177e4c3f41 Linus Torvalds 2005-04-16 938 sc->board_idx = cards_found++;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 939 sc->extra_stats.check = STATCHECK;
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 940 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 941 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
64bef7630ad5b0 Krzysztof Hałasa 2008-07-02 942 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
^1da177e4c3f41 Linus Torvalds 2005-04-16 943
^1da177e4c3f41 Linus Torvalds 2005-04-16 944 sc->lmc_ok = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 945 sc->last_link_status = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 946
^1da177e4c3f41 Linus Torvalds 2005-04-16 @947 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 948 }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx