Skip to contentSkip to conversation

drivers/net/ethernet/xscale/ptp_ixp46x.c:283 ixp46x_ptp_find() warn: variable dereferenced before check 'ixp_clock.ptp_clock' (see line 281)

PATCH In review Dan Carpenter 3 participants 3 messages Oct 11, 2019 – Oct 18, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 17/23 drivers/net/ethernet/xscale/ptp_ixp46x.c:283 ixp46x_ptp_find() warn: variable dereferenced before check 'ixp_clock.ptp_clock' (see line 281)

Hi Arnd,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git ixp4xx-test
head:   1b826e686b390fd1eeb347def38185fefcbd5140
commit: 7ac6c27d7ee1cdef95314be43e4c3854d8f80240 [17/23] ixp4xx_eth: enable compile testing

If you fix the issue, kindly add following tag

smatch warnings:
drivers/net/ethernet/xscale/ptp_ixp46x.c:283 ixp46x_ptp_find() warn: variable dereferenced before check 'ixp_clock.ptp_clock' (see line 281)

# https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/commit/?id=7ac6c27d7ee1cdef95314be43e4c3854d8f80240
git remote add arm-integrator https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git
git remote update arm-integrator
git checkout 7ac6c27d7ee1cdef95314be43e4c3854d8f80240
vim +283 drivers/net/ethernet/xscale/ptp_ixp46x.c

768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  278  int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
32bd93e8f924c2 drivers/ptp/ptp_ixp46x.c                 Richard Cochran 2011-04-22  279  {
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  280  	*regs = ixp_clock.regs;
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26 @281  	*phc_index = ptp_clock_index(ixp_clock.ptp_clock);
                                                                                                                             ^^^^^^^^^^^^^^^^^^^

Dereferenced inside function

768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann 2019-08-26 282
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann 2019-08-26 @283 if (!ixp_clock.ptp_clock)

                                                                                                    ^^^^^^^^^^^^^^^^^^^^

Too late.

768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  284  		return -EPROBE_DEFER;
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  285  
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  286  	return 0;
32bd93e8f924c2 drivers/ptp/ptp_ixp46x.c                 Richard Cochran 2011-04-22  287  }
768672ff6ea477 drivers/net/ethernet/xscale/ptp_ixp46x.c Arnd Bergmann   2019-08-26  288  EXPORT_SYMBOL_GPL(ixp46x_ptp_find);

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#1 lore raw
Quoted 9 lines · Dan Carpenter

Hi Arnd,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git ixp4xx-test
head:   1b826e686b390fd1eeb347def38185fefcbd5140
commit: 7ac6c27d7ee1cdef95314be43e4c3854d8f80240 [17/23] ixp4xx_eth: enable compile testing
Quoted 7 lines

If you fix the issue, kindly add following tag

smatch warnings:
drivers/net/ethernet/xscale/ptp_ixp46x.c:283 ixp46x_ptp_find() warn: variable dereferenced before check 'ixp_clock.ptp_clock' (see line 281)

This is clearly a bug I introduced, thanks a lot for the report!

Again, there is a trivial fix that Linus or I should fold into the original patch:

(quoted diff) +0 -0

b/drivers/net/ethernet/xscale/ptp_ixp46x.c
index bb62c265bb4d..2af8e47dc13b 100644

drivers/net/ethernet/xscale/ptp_ixp46x.c +3 -3
@@ -277,12 +277,12 @@ static int setup_interrupt(int gpio)
 
 int ixp46x_ptp_find(struct ixp46x_ts_regs *__iomem *regs, int *phc_index)
 {
-       *regs = ixp_clock.regs;
-       *phc_index = ptp_clock_index(ixp_clock.ptp_clock);
-
        if (!ixp_clock.ptp_clock)
                return -EPROBE_DEFER;
 
+       *regs = ixp_clock.regs;
+       *phc_index = ptp_clock_index(ixp_clock.ptp_clock);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(ixp46x_ptp_find);

Arnd

#2 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines

smatch warnings:
drivers/net/ethernet/xscale/ptp_ixp46x.c:283 ixp46x_ptp_find() warn: variable dereferenced before check 'ixp_clock.ptp_clock' (see line 281)

This is clearly a bug I introduced, thanks a lot for the report!

Again, there is a trivial fix that Linus or I should fold into the original patch:

I folded it into the patch in my tree.

I'm working to get some of this in a shape that I can start funneling it to ARM-SoC.

Yours,
Linus Walleij