Skip to contentSkip to conversation

drivers/pwm/core.c:1530 pwm_put() warn: variable dereferenced before check 'pwm' (see line 1528)

PATCH In review Dan Carpenter 2 participants 4 messages Apr 2, 2024 – Apr 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1128/2532 drivers/pwm/core.c:1530 pwm_put() warn: variable dereferenced before check 'pwm' (see line 1528)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   a6bd6c9333397f5a0e2667d4d82fef8c970108f2
commit: d60bc2995732489766cbe650fc367e036ff6a0e0 [1128/2532] pwm: Add a struct device to struct pwm_chip
config: m68k-randconfig-r071-20240326 (https://download.01.org/0day-ci/archive/20240331/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 13.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/pwm/core.c:1530 pwm_put() warn: variable dereferenced before check 'pwm' (see line 1528)

vim +/pwm +1530 drivers/pwm/core.c

8138d2ddbcca2a Thierry Reding   2012-03-26  1526  void pwm_put(struct pwm_device *pwm)
8138d2ddbcca2a Thierry Reding   2012-03-26  1527  {
d60bc299573248 Uwe Kleine-König 2024-03-17 @1528  	struct pwm_chip *chip = pwm->chip;
                                                                                ^^^^^^^^^^

Dereference

d60bc299573248 Uwe Kleine-König 2024-03-17 1529
8138d2ddbcca2a Thierry Reding 2012-03-26 @1530 if (!pwm)

                                                            ^^^^

Too late.

8138d2ddbcca2a Thierry Reding   2012-03-26  1531  		return;
8138d2ddbcca2a Thierry Reding   2012-03-26  1532  
8138d2ddbcca2a Thierry Reding   2012-03-26  1533  	mutex_lock(&pwm_lock);
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw

Hello,

Quoted 23 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   a6bd6c9333397f5a0e2667d4d82fef8c970108f2
commit: d60bc2995732489766cbe650fc367e036ff6a0e0 [1128/2532] pwm: Add a struct device to struct pwm_chip
config: m68k-randconfig-r071-20240326 (https://download.01.org/0day-ci/archive/20240331/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 13.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/pwm/core.c:1530 pwm_put() warn: variable dereferenced before check 'pwm' (see line 1528)

vim +/pwm +1530 drivers/pwm/core.c

8138d2ddbcca2a Thierry Reding   2012-03-26  1526  void pwm_put(struct pwm_device *pwm)
8138d2ddbcca2a Thierry Reding   2012-03-26  1527  {
d60bc299573248 Uwe Kleine-König 2024-03-17 @1528  	struct pwm_chip *chip = pwm->chip;
                                                                                ^^^^^^^^^^

Dereference

Quoted 8 lines

d60bc299573248 Uwe Kleine-König 2024-03-17 1529
8138d2ddbcca2a Thierry Reding 2012-03-26 @1530 if (!pwm)

                                                            ^^^^

Too late.

8138d2ddbcca2a Thierry Reding   2012-03-26  1531  		return;
8138d2ddbcca2a Thierry Reding   2012-03-26  1532  
8138d2ddbcca2a Thierry Reding   2012-03-26  1533  	mutex_lock(&pwm_lock);

This is already addressed in fbf632f9dc55.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#2 lore raw
Quoted 13 lines · Uwe Kleine-König

Hello,

Quoted 11 lines
8138d2ddbcca2a Thierry Reding   2012-03-26  1526  void pwm_put(struct pwm_device *pwm)
8138d2ddbcca2a Thierry Reding   2012-03-26  1527  {
d60bc299573248 Uwe Kleine-König 2024-03-17 @1528  	struct pwm_chip *chip = pwm->chip;
                                                                                ^^^^^^^^^^

Dereference

d60bc299573248 Uwe Kleine-König 2024-03-17 1529
8138d2ddbcca2a Thierry Reding 2012-03-26 @1530 if (!pwm)

                                                            ^^^^

Too late.

Quoted 6 lines
Quoted 3 lines
8138d2ddbcca2a Thierry Reding   2012-03-26  1531  		return;
8138d2ddbcca2a Thierry Reding   2012-03-26  1532  
8138d2ddbcca2a Thierry Reding   2012-03-26  1533  	mutex_lock(&pwm_lock);

This is already addressed in fbf632f9dc55.

Apparently we never merged that commit, though... It's not in linux-next.

regards,
dan carpenter

#3 lore raw

Hello Dan,

Quoted 18 lines · Dan Carpenter
Quoted 17 lines · Uwe Kleine-König

Hello,

Quoted 14 lines
8138d2ddbcca2a Thierry Reding   2012-03-26  1526  void pwm_put(struct pwm_device *pwm)
8138d2ddbcca2a Thierry Reding   2012-03-26  1527  {
d60bc299573248 Uwe Kleine-König 2024-03-17 @1528  	struct pwm_chip *chip = pwm->chip;
                                                                                ^^^^^^^^^^

Dereference

d60bc299573248 Uwe Kleine-König 2024-03-17 1529
8138d2ddbcca2a Thierry Reding 2012-03-26 @1530 if (!pwm)

                                                            ^^^^

Too late.

8138d2ddbcca2a Thierry Reding   2012-03-26  1531  		return;
8138d2ddbcca2a Thierry Reding   2012-03-26  1532  
8138d2ddbcca2a Thierry Reding   2012-03-26  1533  	mutex_lock(&pwm_lock);
Quoted 5 lines
Quoted 2 lines

This is already addressed in fbf632f9dc55.

Apparently we never merged that commit, though... It's not in linux-next.

Oh, I recently dropped a few commits from my for-next branch and this one was (wrongly) among them. Thanks for paying attention, it's back now.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |