Dan Carpenter
2023-Nov-07 14:32 UTC
[Nouveau] [bug report] drm/nouveau/mmu/r535: initial support
Hello Ben Skeggs, The patch 5bf0257136a2: "drm/nouveau/mmu/r535: initial support" from Sep 19, 2023 (linux-next), leads to the following Smatch static checker warning: drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c:171 r535_bar_new_() error: uninitialized symbol 'bar'. drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c 147 int 148 r535_bar_new_(const struct nvkm_bar_func *hw, struct nvkm_device *device, 149 enum nvkm_subdev_type type, int inst, struct nvkm_bar **pbar) 150 { 151 struct nvkm_bar_func *rm; 152 struct nvkm_bar *bar; 153 int ret; 154 155 if (!(rm = kzalloc(sizeof(*rm), GFP_KERNEL))) 156 return -ENOMEM; 157 158 rm->dtor = r535_bar_dtor; 159 rm->oneinit = hw->oneinit; 160 rm->bar1.init = r535_bar_bar1_init; 161 rm->bar1.fini = r535_bar_bar1_fini; 162 rm->bar1.wait = r535_bar_bar1_wait; 163 rm->bar1.vmm = hw->bar1.vmm; 164 rm->bar2.init = r535_bar_bar2_init; 165 rm->bar2.fini = r535_bar_bar2_fini; 166 rm->bar2.wait = r535_bar_bar2_wait; 167 rm->bar2.vmm = hw->bar2.vmm; 168 rm->flush = r535_bar_flush; 169 170 ret = gf100_bar_new_(rm, device, type, inst, &bar); --> 171 *pbar = bar; 172 if (ret) { 173 if (!bar) ^^^^ If gf100_bar_new_() fails then bar isn't initialized. Do we really need to initialize bar to NULL on error? If so then we should do it before the "rm = kzalloc()". 174 kfree(rm); 175 return ret; 176 } 177 178 bar->flushBAR2PhysMode = ioremap(device->func->resource_addr(device, 3), PAGE_SIZE); 179 if (!bar->flushBAR2PhysMode) 180 return -ENOMEM; 181 182 bar->flushBAR2 = bar->flushBAR2PhysMode; 183 184 gf100_bar(*pbar)->bar2_halve = true; 185 return 0; 186 } regards, dan carpenter
Timur Tabi
2023-Nov-07 15:06 UTC
[Nouveau] [bug report] drm/nouveau/mmu/r535: initial support
On Tue, 2023-11-07 at 17:32 +0300, Dan Carpenter wrote:> ??? 170???????? ret = gf100_bar_new_(rm, device, type, inst, &bar); > --> 171???????? *pbar = bar; > ??? 172???????? if (ret) { > ??? 173???????????????? if (!bar) > ??????????????????????????? ^^^^ > If gf100_bar_new_() fails then bar isn't initialized.? Do we really > need to initialize bar to NULL on error?? If so then we should do it > before the "rm = kzalloc()".We can just do this: struct nvkm_bar *bar = NULL;