[Nouveau] [PATCH] drm/nouveau: Fix potential memory access error in nouveau_debugfs_pstate_get()

kbuild test robot lkp at intel.com
Wed Aug 1 09:13:14 UTC 2018


Hi Lyude,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.18-rc7 next-20180731]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Lyude-Paul/drm-nouveau-Fix-potential-memory-access-error-in-nouveau_debugfs_pstate_get/20180801-155246
config: i386-randconfig-a1-201830 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   drivers/gpu//drm/nouveau/nouveau_debugfs.c: In function 'nouveau_debugfs_pstate_get':
>> drivers/gpu//drm/nouveau/nouveau_debugfs.c:54:22: warning: 'debugfs' is used uninitialized in this function [-Wuninitialized]
     struct nvif_object *ctrl = &debugfs->ctrl;
                         ^

vim +/debugfs +54 drivers/gpu//drm/nouveau/nouveau_debugfs.c

33b903e8 Marcin Slusarz 2013-02-08   48  
6e9fc177 Karol Herbst   2015-07-30   49  static int
6e9fc177 Karol Herbst   2015-07-30   50  nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
6e9fc177 Karol Herbst   2015-07-30   51  {
1a54082a Noralf Trønnes 2017-01-26   52  	struct drm_device *drm = m->private;
11a2501e Lyude Paul     2018-07-30   53  	struct nouveau_debugfs *debugfs;
6e9fc177 Karol Herbst   2015-07-30  @54  	struct nvif_object *ctrl = &debugfs->ctrl;
6e9fc177 Karol Herbst   2015-07-30   55  	struct nvif_control_pstate_info_v0 info = {};
6e9fc177 Karol Herbst   2015-07-30   56  	int ret, i;
6e9fc177 Karol Herbst   2015-07-30   57  
11a2501e Lyude Paul     2018-07-30   58  	if (!drm)
6e9fc177 Karol Herbst   2015-07-30   59  		return -ENODEV;
11a2501e Lyude Paul     2018-07-30   60  	debugfs = nouveau_debugfs(drm);
6e9fc177 Karol Herbst   2015-07-30   61  
6e9fc177 Karol Herbst   2015-07-30   62  	ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_INFO, &info, sizeof(info));
6e9fc177 Karol Herbst   2015-07-30   63  	if (ret)
6e9fc177 Karol Herbst   2015-07-30   64  		return ret;
6e9fc177 Karol Herbst   2015-07-30   65  
6e9fc177 Karol Herbst   2015-07-30   66  	for (i = 0; i < info.count + 1; i++) {
6e9fc177 Karol Herbst   2015-07-30   67  		const s32 state = i < info.count ? i :
6e9fc177 Karol Herbst   2015-07-30   68  			NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT;
6e9fc177 Karol Herbst   2015-07-30   69  		struct nvif_control_pstate_attr_v0 attr = {
6e9fc177 Karol Herbst   2015-07-30   70  			.state = state,
6e9fc177 Karol Herbst   2015-07-30   71  			.index = 0,
6e9fc177 Karol Herbst   2015-07-30   72  		};
6e9fc177 Karol Herbst   2015-07-30   73  
6e9fc177 Karol Herbst   2015-07-30   74  		ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
6e9fc177 Karol Herbst   2015-07-30   75  				&attr, sizeof(attr));
6e9fc177 Karol Herbst   2015-07-30   76  		if (ret)
6e9fc177 Karol Herbst   2015-07-30   77  			return ret;
6e9fc177 Karol Herbst   2015-07-30   78  
6e9fc177 Karol Herbst   2015-07-30   79  		if (i < info.count)
6e9fc177 Karol Herbst   2015-07-30   80  			seq_printf(m, "%02x:", attr.state);
6e9fc177 Karol Herbst   2015-07-30   81  		else
6e9fc177 Karol Herbst   2015-07-30   82  			seq_printf(m, "%s:", info.pwrsrc == 0 ? "DC" :
6e9fc177 Karol Herbst   2015-07-30   83  					     info.pwrsrc == 1 ? "AC" : "--");
6e9fc177 Karol Herbst   2015-07-30   84  
6e9fc177 Karol Herbst   2015-07-30   85  		attr.index = 0;
6e9fc177 Karol Herbst   2015-07-30   86  		do {
6e9fc177 Karol Herbst   2015-07-30   87  			attr.state = state;
6e9fc177 Karol Herbst   2015-07-30   88  			ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
6e9fc177 Karol Herbst   2015-07-30   89  					&attr, sizeof(attr));
6e9fc177 Karol Herbst   2015-07-30   90  			if (ret)
6e9fc177 Karol Herbst   2015-07-30   91  				return ret;
6e9fc177 Karol Herbst   2015-07-30   92  
6e9fc177 Karol Herbst   2015-07-30   93  			seq_printf(m, " %s %d", attr.name, attr.min);
6e9fc177 Karol Herbst   2015-07-30   94  			if (attr.min != attr.max)
6e9fc177 Karol Herbst   2015-07-30   95  				seq_printf(m, "-%d", attr.max);
6e9fc177 Karol Herbst   2015-07-30   96  			seq_printf(m, " %s", attr.unit);
6e9fc177 Karol Herbst   2015-07-30   97  		} while (attr.index);
6e9fc177 Karol Herbst   2015-07-30   98  
6e9fc177 Karol Herbst   2015-07-30   99  		if (state >= 0) {
6e9fc177 Karol Herbst   2015-07-30  100  			if (info.ustate_ac == state)
6e9fc177 Karol Herbst   2015-07-30  101  				seq_printf(m, " AC");
6e9fc177 Karol Herbst   2015-07-30  102  			if (info.ustate_dc == state)
6e9fc177 Karol Herbst   2015-07-30  103  				seq_printf(m, " DC");
6e9fc177 Karol Herbst   2015-07-30  104  			if (info.pstate == state)
6e9fc177 Karol Herbst   2015-07-30  105  				seq_printf(m, " *");
6e9fc177 Karol Herbst   2015-07-30  106  		} else {
6e9fc177 Karol Herbst   2015-07-30  107  			if (info.ustate_ac < -1)
6e9fc177 Karol Herbst   2015-07-30  108  				seq_printf(m, " AC");
6e9fc177 Karol Herbst   2015-07-30  109  			if (info.ustate_dc < -1)
6e9fc177 Karol Herbst   2015-07-30  110  				seq_printf(m, " DC");
6e9fc177 Karol Herbst   2015-07-30  111  		}
6e9fc177 Karol Herbst   2015-07-30  112  
6e9fc177 Karol Herbst   2015-07-30  113  		seq_printf(m, "\n");
6e9fc177 Karol Herbst   2015-07-30  114  	}
6e9fc177 Karol Herbst   2015-07-30  115  
6e9fc177 Karol Herbst   2015-07-30  116  	return 0;
6e9fc177 Karol Herbst   2015-07-30  117  }
6e9fc177 Karol Herbst   2015-07-30  118  

:::::: The code at line 54 was first introduced by commit
:::::: 6e9fc177399f08446293fec7607913fdbc95e191 drm/nouveau/debugfs: add copy of sysfs pstate interface ported to debugfs

:::::: TO: Karol Herbst <nouveau at karolherbst.de>
:::::: CC: Ben Skeggs <bskeggs at redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 29403 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/nouveau/attachments/20180801/13409014/attachment-0001.gz>


More information about the Nouveau mailing list