All of lore.kernel.org
 help / color / mirror / Atom feed
* [chanwoo:devfreq-testing-sysfs 10/11] drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
@ 2020-10-20 14:36 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-10-20 14:36 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 10307 bytes --]

CC: kbuild-all(a)lists.01.org
TO: Chanwoo Choi <cw00.choi@samsung.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git devfreq-testing-sysfs
head:   39383545c0e470caa41717dcde9b208a2436a4d3
commit: 20aff4c41da16a69a8a80670a2892e08b51dd4aa [10/11] PM / devfreq: Remove redundant governor_name from struct devfreq
:::::: branch date: 8 hours ago
:::::: commit date: 8 hours ago
config: x86_64-randconfig-m001-20201020 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

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

New smatch warnings:
drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
drivers/devfreq/devfreq.c:1317 devfreq_remove_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1314)

Old smatch warnings:
drivers/devfreq/devfreq.c:942 devfreq_add_device() warn: passing zero to 'ERR_PTR'

vim +1255 drivers/devfreq/devfreq.c

59031956052876 Lukasz Luba    2018-12-05  1221  
3aa173b8db200b Nishanth Menon 2012-10-29  1222  /**
3aa173b8db200b Nishanth Menon 2012-10-29  1223   * devfreq_add_governor() - Add devfreq governor
3aa173b8db200b Nishanth Menon 2012-10-29  1224   * @governor:	the devfreq governor to be added
3aa173b8db200b Nishanth Menon 2012-10-29  1225   */
3aa173b8db200b Nishanth Menon 2012-10-29  1226  int devfreq_add_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1227  {
3aa173b8db200b Nishanth Menon 2012-10-29  1228  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1229  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1230  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1231  
3aa173b8db200b Nishanth Menon 2012-10-29  1232  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1233  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1234  		return -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1235  	}
9f3bdd4f937a75 Axel Lin       2011-11-14  1236  
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1237  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1238  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1239  	if (!IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1240  		pr_err("%s: governor %s already registered\n", __func__,
3aa173b8db200b Nishanth Menon 2012-10-29  1241  		       g->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1242  		err = -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1243  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1244  	}
3aa173b8db200b Nishanth Menon 2012-10-29  1245  
3aa173b8db200b Nishanth Menon 2012-10-29  1246  	list_add(&governor->node, &devfreq_governor_list);
3aa173b8db200b Nishanth Menon 2012-10-29  1247  
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1248  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1249  		int ret = 0;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1250  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1251  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1252  		if (!strncmp(devfreq->governor->name, governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1253  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1254  			/* The following should never occur */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1255  			if (devfreq->governor) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1256  				dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1257  					 "%s: Governor %s already present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1258  					 __func__, devfreq->governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1259  				ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1260  							DEVFREQ_GOV_STOP, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1261  				if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1262  					dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1263  						 "%s: Governor %s stop = %d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1264  						 __func__,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1265  						 devfreq->governor->name, ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1266  				}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1267  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1268  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1269  			devfreq->governor = governor;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1270  			ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1271  						DEVFREQ_GOV_START, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1272  			if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1273  				dev_warn(dev, "%s: Governor %s start=%d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1274  					 __func__, devfreq->governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1275  					 ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1276  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1277  		}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1278  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1279  
3aa173b8db200b Nishanth Menon 2012-10-29  1280  err_out:
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1281  	mutex_unlock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1282  
3aa173b8db200b Nishanth Menon 2012-10-29  1283  	return err;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1284  }
3aa173b8db200b Nishanth Menon 2012-10-29  1285  EXPORT_SYMBOL(devfreq_add_governor);
3aa173b8db200b Nishanth Menon 2012-10-29  1286  
3aa173b8db200b Nishanth Menon 2012-10-29  1287  /**
bafeb42bd80fb2 MyungJoo Ham   2016-11-09  1288   * devfreq_remove_governor() - Remove devfreq feature from a device.
3aa173b8db200b Nishanth Menon 2012-10-29  1289   * @governor:	the devfreq governor to be removed
3aa173b8db200b Nishanth Menon 2012-10-29  1290   */
3aa173b8db200b Nishanth Menon 2012-10-29  1291  int devfreq_remove_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1292  {
3aa173b8db200b Nishanth Menon 2012-10-29  1293  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1294  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1295  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1296  
3aa173b8db200b Nishanth Menon 2012-10-29  1297  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1298  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1299  		return -EINVAL;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1300  	}
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1301  
3aa173b8db200b Nishanth Menon 2012-10-29  1302  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1303  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1304  	if (IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1305  		pr_err("%s: governor %s not registered\n", __func__,
b9e1c8e821e776 Sachin Kamat   2012-11-21  1306  		       governor->name);
f9c08e2acbbed1 Sachin Kamat   2012-11-21  1307  		err = PTR_ERR(g);
3aa173b8db200b Nishanth Menon 2012-10-29  1308  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1309  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1310  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1311  		int ret;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1312  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1313  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1314  		if (!strncmp(devfreq->governor->name, governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1315  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1316  			/* we should have a devfreq governor! */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1317  			if (!devfreq->governor) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1318  				dev_warn(dev, "%s: Governor %s NOT present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1319  					 __func__, governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1320  				continue;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1321  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1322  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1323  			ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1324  						DEVFREQ_GOV_STOP, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1325  			if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1326  				dev_warn(dev, "%s: Governor %s stop=%d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1327  					 __func__, devfreq->governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1328  					 ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1329  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1330  			devfreq->governor = NULL;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1331  		}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1332  	}
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1333  
3aa173b8db200b Nishanth Menon 2012-10-29  1334  	list_del(&governor->node);
3aa173b8db200b Nishanth Menon 2012-10-29  1335  err_out:
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1336  	mutex_unlock(&devfreq_list_lock);
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1337  
3aa173b8db200b Nishanth Menon 2012-10-29  1338  	return err;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1339  }
3aa173b8db200b Nishanth Menon 2012-10-29  1340  EXPORT_SYMBOL(devfreq_remove_governor);
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1341  

:::::: The code at line 1255 was first introduced by commit
:::::: 1b5c1be2c88e8445a20fa1929e26c37e7ca8c926 PM / devfreq: map devfreq drivers to governor using name

:::::: TO: Nishanth Menon <nm@ti.com>
:::::: CC: MyungJoo Ham <myungjoo.ham@samsung.com>

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30607 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [chanwoo:devfreq-testing-sysfs 10/11] drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
@ 2020-10-27 10:31 ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-10-27 10:31 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8810 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git devfreq-testing-sysfs
head:   39383545c0e470caa41717dcde9b208a2436a4d3
commit: 20aff4c41da16a69a8a80670a2892e08b51dd4aa [10/11] PM / devfreq: Remove redundant governor_name from struct devfreq
config: x86_64-randconfig-m001-20201020 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

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

New smatch warnings:
drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
drivers/devfreq/devfreq.c:1317 devfreq_remove_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1314)

vim +1255 drivers/devfreq/devfreq.c

3aa173b8db200b Nishanth Menon 2012-10-29  1226  int devfreq_add_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1227  {
3aa173b8db200b Nishanth Menon 2012-10-29  1228  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1229  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1230  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1231  
3aa173b8db200b Nishanth Menon 2012-10-29  1232  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1233  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1234  		return -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1235  	}
9f3bdd4f937a75 Axel Lin       2011-11-14  1236  
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1237  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1238  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1239  	if (!IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1240  		pr_err("%s: governor %s already registered\n", __func__,
3aa173b8db200b Nishanth Menon 2012-10-29  1241  		       g->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1242  		err = -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1243  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1244  	}
3aa173b8db200b Nishanth Menon 2012-10-29  1245  
3aa173b8db200b Nishanth Menon 2012-10-29  1246  	list_add(&governor->node, &devfreq_governor_list);
3aa173b8db200b Nishanth Menon 2012-10-29  1247  
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1248  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1249  		int ret = 0;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1250  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1251  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1252  		if (!strncmp(devfreq->governor->name, governor->name,
                                                                             ^^^^^^^^^^^^^^^^^^^^^^^
Dereferenced here.


1b5c1be2c88e84 Nishanth Menon 2012-10-29  1253  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1254  			/* The following should never occur */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1255  			if (devfreq->governor) {
                                                                            ^^^^^^^^^^^^^^^^^
Checked too late.  The comment say that this can't happen so hopefully
this whole if statement can be deleted.

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1256  				dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1257  					 "%s: Governor %s already present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1258  					 __func__, devfreq->governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1259  				ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1260  							DEVFREQ_GOV_STOP, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1261  				if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1262  					dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1263  						 "%s: Governor %s stop = %d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1264  						 __func__,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1265  						 devfreq->governor->name, ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1266  				}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1267  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1268  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1269  			devfreq->governor = governor;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1270  			ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1271  						DEVFREQ_GOV_START, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1272  			if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1273  				dev_warn(dev, "%s: Governor %s start=%d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1274  					 __func__, devfreq->governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1275  					 ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1276  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1277  		}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1278  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1279  
3aa173b8db200b Nishanth Menon 2012-10-29  1280  err_out:
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1281  	mutex_unlock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1282  
3aa173b8db200b Nishanth Menon 2012-10-29  1283  	return err;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1284  }
3aa173b8db200b Nishanth Menon 2012-10-29  1285  EXPORT_SYMBOL(devfreq_add_governor);
3aa173b8db200b Nishanth Menon 2012-10-29  1286  
3aa173b8db200b Nishanth Menon 2012-10-29  1287  /**
bafeb42bd80fb2 MyungJoo Ham   2016-11-09  1288   * devfreq_remove_governor() - Remove devfreq feature from a device.
3aa173b8db200b Nishanth Menon 2012-10-29  1289   * @governor:	the devfreq governor to be removed
3aa173b8db200b Nishanth Menon 2012-10-29  1290   */
3aa173b8db200b Nishanth Menon 2012-10-29  1291  int devfreq_remove_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1292  {
3aa173b8db200b Nishanth Menon 2012-10-29  1293  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1294  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1295  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1296  
3aa173b8db200b Nishanth Menon 2012-10-29  1297  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1298  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1299  		return -EINVAL;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1300  	}
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1301  
3aa173b8db200b Nishanth Menon 2012-10-29  1302  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1303  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1304  	if (IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1305  		pr_err("%s: governor %s not registered\n", __func__,
b9e1c8e821e776 Sachin Kamat   2012-11-21  1306  		       governor->name);
f9c08e2acbbed1 Sachin Kamat   2012-11-21  1307  		err = PTR_ERR(g);
3aa173b8db200b Nishanth Menon 2012-10-29  1308  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1309  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1310  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1311  		int ret;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1312  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1313  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1314  		if (!strncmp(devfreq->governor->name, governor->name,
                                                                             ^^^^^^^^^^^^^^^^^^^^^^^
Dereference

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1315  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1316  			/* we should have a devfreq governor! */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1317  			if (!devfreq->governor) {
                                                                             ^^^^^^^^^^^^^^^^^
Too late!

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1318  				dev_warn(dev, "%s: Governor %s NOT present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1319  					 __func__, governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1320  				continue;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1321  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1322  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1323  			ret = devfreq->governor->event_handler(devfreq,

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30607 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [chanwoo:devfreq-testing-sysfs 10/11] drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
@ 2020-10-27 10:31 ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-10-27 10:31 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 8810 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git devfreq-testing-sysfs
head:   39383545c0e470caa41717dcde9b208a2436a4d3
commit: 20aff4c41da16a69a8a80670a2892e08b51dd4aa [10/11] PM / devfreq: Remove redundant governor_name from struct devfreq
config: x86_64-randconfig-m001-20201020 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

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

New smatch warnings:
drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252)
drivers/devfreq/devfreq.c:1317 devfreq_remove_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1314)

vim +1255 drivers/devfreq/devfreq.c

3aa173b8db200b Nishanth Menon 2012-10-29  1226  int devfreq_add_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1227  {
3aa173b8db200b Nishanth Menon 2012-10-29  1228  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1229  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1230  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1231  
3aa173b8db200b Nishanth Menon 2012-10-29  1232  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1233  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1234  		return -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1235  	}
9f3bdd4f937a75 Axel Lin       2011-11-14  1236  
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1237  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1238  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1239  	if (!IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1240  		pr_err("%s: governor %s already registered\n", __func__,
3aa173b8db200b Nishanth Menon 2012-10-29  1241  		       g->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1242  		err = -EINVAL;
3aa173b8db200b Nishanth Menon 2012-10-29  1243  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1244  	}
3aa173b8db200b Nishanth Menon 2012-10-29  1245  
3aa173b8db200b Nishanth Menon 2012-10-29  1246  	list_add(&governor->node, &devfreq_governor_list);
3aa173b8db200b Nishanth Menon 2012-10-29  1247  
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1248  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1249  		int ret = 0;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1250  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1251  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1252  		if (!strncmp(devfreq->governor->name, governor->name,
                                                                             ^^^^^^^^^^^^^^^^^^^^^^^
Dereferenced here.


1b5c1be2c88e84 Nishanth Menon 2012-10-29  1253  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1254  			/* The following should never occur */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1255  			if (devfreq->governor) {
                                                                            ^^^^^^^^^^^^^^^^^
Checked too late.  The comment say that this can't happen so hopefully
this whole if statement can be deleted.

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1256  				dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1257  					 "%s: Governor %s already present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1258  					 __func__, devfreq->governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1259  				ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1260  							DEVFREQ_GOV_STOP, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1261  				if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1262  					dev_warn(dev,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1263  						 "%s: Governor %s stop = %d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1264  						 __func__,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1265  						 devfreq->governor->name, ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1266  				}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1267  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1268  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1269  			devfreq->governor = governor;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1270  			ret = devfreq->governor->event_handler(devfreq,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1271  						DEVFREQ_GOV_START, NULL);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1272  			if (ret) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1273  				dev_warn(dev, "%s: Governor %s start=%d\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1274  					 __func__, devfreq->governor->name,
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1275  					 ret);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1276  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1277  		}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1278  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1279  
3aa173b8db200b Nishanth Menon 2012-10-29  1280  err_out:
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1281  	mutex_unlock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1282  
3aa173b8db200b Nishanth Menon 2012-10-29  1283  	return err;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1284  }
3aa173b8db200b Nishanth Menon 2012-10-29  1285  EXPORT_SYMBOL(devfreq_add_governor);
3aa173b8db200b Nishanth Menon 2012-10-29  1286  
3aa173b8db200b Nishanth Menon 2012-10-29  1287  /**
bafeb42bd80fb2 MyungJoo Ham   2016-11-09  1288   * devfreq_remove_governor() - Remove devfreq feature from a device.
3aa173b8db200b Nishanth Menon 2012-10-29  1289   * @governor:	the devfreq governor to be removed
3aa173b8db200b Nishanth Menon 2012-10-29  1290   */
3aa173b8db200b Nishanth Menon 2012-10-29  1291  int devfreq_remove_governor(struct devfreq_governor *governor)
3aa173b8db200b Nishanth Menon 2012-10-29  1292  {
3aa173b8db200b Nishanth Menon 2012-10-29  1293  	struct devfreq_governor *g;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1294  	struct devfreq *devfreq;
3aa173b8db200b Nishanth Menon 2012-10-29  1295  	int err = 0;
3aa173b8db200b Nishanth Menon 2012-10-29  1296  
3aa173b8db200b Nishanth Menon 2012-10-29  1297  	if (!governor) {
3aa173b8db200b Nishanth Menon 2012-10-29  1298  		pr_err("%s: Invalid parameters.\n", __func__);
3aa173b8db200b Nishanth Menon 2012-10-29  1299  		return -EINVAL;
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1300  	}
a3c98b8b2ede1f MyungJoo Ham   2011-10-02  1301  
3aa173b8db200b Nishanth Menon 2012-10-29  1302  	mutex_lock(&devfreq_list_lock);
3aa173b8db200b Nishanth Menon 2012-10-29  1303  	g = find_devfreq_governor(governor->name);
3aa173b8db200b Nishanth Menon 2012-10-29  1304  	if (IS_ERR(g)) {
3aa173b8db200b Nishanth Menon 2012-10-29  1305  		pr_err("%s: governor %s not registered\n", __func__,
b9e1c8e821e776 Sachin Kamat   2012-11-21  1306  		       governor->name);
f9c08e2acbbed1 Sachin Kamat   2012-11-21  1307  		err = PTR_ERR(g);
3aa173b8db200b Nishanth Menon 2012-10-29  1308  		goto err_out;
3aa173b8db200b Nishanth Menon 2012-10-29  1309  	}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1310  	list_for_each_entry(devfreq, &devfreq_list, node) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1311  		int ret;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1312  		struct device *dev = devfreq->dev.parent;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1313  
20aff4c41da16a Chanwoo Choi   2020-10-20 @1314  		if (!strncmp(devfreq->governor->name, governor->name,
                                                                             ^^^^^^^^^^^^^^^^^^^^^^^
Dereference

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1315  			     DEVFREQ_NAME_LEN)) {
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1316  			/* we should have a devfreq governor! */
1b5c1be2c88e84 Nishanth Menon 2012-10-29 @1317  			if (!devfreq->governor) {
                                                                             ^^^^^^^^^^^^^^^^^
Too late!

1b5c1be2c88e84 Nishanth Menon 2012-10-29  1318  				dev_warn(dev, "%s: Governor %s NOT present\n",
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1319  					 __func__, governor->name);
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1320  				continue;
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1321  				/* Fall through */
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1322  			}
1b5c1be2c88e84 Nishanth Menon 2012-10-29  1323  			ret = devfreq->governor->event_handler(devfreq,

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 30607 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-27 10:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-27 10:31 [chanwoo:devfreq-testing-sysfs 10/11] drivers/devfreq/devfreq.c:1255 devfreq_add_governor() warn: variable dereferenced before check 'devfreq->governor' (see line 1252) Dan Carpenter
2020-10-27 10:31 ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2020-10-20 14:36 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.