RE: drivers/net/ethernet/freescale/gianfar.c:580 gfar_parse_group() warn: 'grp->regs' not released on lines: 517.
From: Leo Li
Date: Mon Nov 16 2020 - 20:45:19 EST
> -----Original Message-----
> From: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> Sent: Monday, November 16, 2020 3:25 AM
> To: kbuild@xxxxxxxxxxxx; Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
> Cc: lkp@xxxxxxxxx; Dan Carpenter <error27@xxxxxxxxx>; kbuild-
> all@xxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; Leo Li <leoyang.li@xxxxxxx>;
> Timur Tabi <timur@xxxxxxxxxx>
> Subject: drivers/net/ethernet/freescale/gianfar.c:580 gfar_parse_group()
> warn: 'grp->regs' not released on lines: 517.
>
> Hi Rasmus,
>
> First bad commit (maybe != root cause):
>
> tree:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ke
> rnel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&a
> mp;data=04%7C01%7Cleoyang.li%40nxp.com%7Cfcd86334161e4c85f12408d8
> 8a11d649%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6374111565
> 08189838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoi
> V2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Zvr6xt8Ew
> NKnUbBs1NMdnLf8xfeYbDGy1yASNs21pKU%3D&reserved=0 master
> head: f01c30de86f1047e9bae1b1b1417b0ce8dcd15b1
> commit: 5a35435ef4e6e4bd2aabd6706b146b298a9cffe5 soc: fsl: qe: remove
> PPC32 dependency from CONFIG_QUICC_ENGINE
It is strange that this driver is not related to the commit above.
> config: powerpc64-randconfig-m031-20201113 (attached as .config)
> compiler: powerpc64-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>
>
> smatch warnings:
> drivers/net/ethernet/freescale/gianfar.c:580 gfar_parse_group() warn: 'grp-
> >regs' not released on lines: 517.
>
> vim +580 drivers/net/ethernet/freescale/gianfar.c
>
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 491 static int gfar_parse_group(struct device_node *np,
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 492 struct gfar_private *priv, const char *model)
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 493 {
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 494 struct gfar_priv_grp *grp = &priv->gfargrp[priv-
> >num_grps];
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 495 int i;
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 496
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 497 for (i = 0; i < GFAR_NUM_IRQS; i++) {
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 498 grp->irqinfo[i] = kzalloc(sizeof(struct
> gfar_irqinfo),
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 499 GFP_KERNEL);
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 500 if (!grp->irqinfo[i])
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 501 return -ENOMEM;
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 502 }
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 503
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 504 grp->regs = of_iomap(np, 0);
> ^^^^^^^^^^^^^^^
>
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 505 if (!grp->regs)
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 506 return -ENOMEM;
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 507
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 508 gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np,
> 0);
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 509
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 510 /* If we aren't the FEC we have multiple interrupts */
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 511 if (model && strcasecmp(model, "FEC")) {
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 512 gfar_irq(grp, RX)->irq =
> irq_of_parse_and_map(np, 1);
> ee873fda3bec7c6 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 513 gfar_irq(grp, ER)->irq =
> irq_of_parse_and_map(np, 2);
> fea0f6650979a4f drivers/net/ethernet/freescale/gianfar.c Mark Brown
> 2015-11-26 514 if (!gfar_irq(grp, TX)->irq ||
> fea0f6650979a4f drivers/net/ethernet/freescale/gianfar.c Mark Brown
> 2015-11-26 515 !gfar_irq(grp, RX)->irq ||
> fea0f6650979a4f drivers/net/ethernet/freescale/gianfar.c Mark Brown
> 2015-11-26 516 !gfar_irq(grp, ER)->irq)
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 517 return -EINVAL;
>
> This should unmap "grp->regs".
This variable is unmapped in the caller with a wholesale cleanup function unmap_group_regs(). Probably a false positive for smatch?
>
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 518 }
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 519
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 520 grp->priv = priv;
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 521 spin_lock_init(&grp->grplock);
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 522 if (priv->mode == MQ_MG_MODE) {
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 523 u32 rxq_mask, txq_mask;
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 524 int ret;
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 525
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 526 grp->rx_bit_map = (DEFAULT_MAPPING >>
> priv->num_grps);
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 527 grp->tx_bit_map = (DEFAULT_MAPPING >>
> priv->num_grps);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 528
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 529 ret = of_property_read_u32(np, "fsl,rx-bit-
> map", &rxq_mask);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 530 if (!ret) {
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 531 grp->rx_bit_map = rxq_mask ?
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 532 rxq_mask : (DEFAULT_MAPPING >>
> priv->num_grps);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 533 }
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 534
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 535 ret = of_property_read_u32(np, "fsl,tx-bit-
> map", &txq_mask);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 536 if (!ret) {
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 537 grp->tx_bit_map = txq_mask ?
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 538 txq_mask : (DEFAULT_MAPPING >>
> priv->num_grps);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 539 }
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 540
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 541 if (priv->poll_mode == GFAR_SQ_POLLING) {
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 542 /* One Q per interrupt group: Q0 to
> G0, Q1 to G1 */
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 543 grp->rx_bit_map =
> (DEFAULT_MAPPING >> priv->num_grps);
> 559176415cc663f drivers/net/ethernet/freescale/gianfar.c Jingchang Lu
> 2015-03-13 544 grp->tx_bit_map =
> (DEFAULT_MAPPING >> priv->num_grps);
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 545 }
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 546 } else {
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 547 grp->rx_bit_map = 0xFF;
> 5fedcc14d40e355 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2013-01-29 548 grp->tx_bit_map = 0xFF;
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 549 }
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 550
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 551 /* bit_map's MSB is q0 (from q0 to q7) but,
> for_each_set_bit parses
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 552 * right to left, so we need to revert the 8 bits to get
> the q index
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 553 */
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 554 grp->rx_bit_map = bitrev8(grp->rx_bit_map);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 555 grp->tx_bit_map = bitrev8(grp->tx_bit_map);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 556
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 557 /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE
> values,
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 558 * also assign queues to groups
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 559 */
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 560 for_each_set_bit(i, &grp->rx_bit_map, priv-
> >num_rx_queues) {
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 561 if (!grp->rx_queue)
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 562 grp->rx_queue = priv->rx_queue[i];
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 563 grp->num_rx_queues++;
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 564 grp->rstat |= (RSTAT_CLEAR_RHALT >> i);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 565 priv->rqueue |= ((RQUEUE_EN0 |
> RQUEUE_EX0) >> i);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 566 priv->rx_queue[i]->grp = grp;
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 567 }
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 568
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 569 for_each_set_bit(i, &grp->tx_bit_map, priv-
> >num_tx_queues) {
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 570 if (!grp->tx_queue)
> 71ff9e3df7e1c5d drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-03-07 571 grp->tx_queue = priv->tx_queue[i];
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 572 grp->num_tx_queues++;
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 573 grp->tstat |= (TSTAT_CLEAR_THALT >> i);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 574 priv->tqueue |= (TQUEUE_EN0 >> i);
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 575 priv->tx_queue[i]->grp = grp;
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 576 }
> 208627883ecfaa1 drivers/net/ethernet/freescale/gianfar.c Claudiu Manoil
> 2014-02-17 577
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 578 priv->num_grps++;
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 579
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 @580 return 0;
> 46ceb60ca80fa07 drivers/net/gianfar.c Sandeep Gopalpet 2009-11-
> 02 581 }
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.0
> 1.org%2Fhyperkitty%2Flist%2Fkbuild-
> all%40lists.01.org&data=04%7C01%7Cleoyang.li%40nxp.com%7Cfcd8633
> 4161e4c85f12408d88a11d649%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%
> 7C0%7C637411156508189838%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4
> wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&a
> mp;sdata=LD7l%2FaKN%2FrmZp3Z21TzF1vP1B92fMJ48st55fTdLbx4%3D&
> ;reserved=0