Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: lantiq: check the return value of kzalloc()

kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check the
return value of it to prevent potential wrong memory access or
memory leak.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Xiaoke Wang and committed by
Thomas Bogendoerfer
34123208 f93e2a10

+34 -16
+2
arch/mips/lantiq/falcon/sysctrl.c
··· 167 167 { 168 168 struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL); 169 169 170 + if (!clk) 171 + return; 170 172 clk->cl.dev_id = dev; 171 173 clk->cl.con_id = NULL; 172 174 clk->cl.clk = clk;
+2
arch/mips/lantiq/xway/gptu.c
··· 122 122 { 123 123 struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL); 124 124 125 + if (!clk) 126 + return; 125 127 clk->cl.dev_id = dev_name(dev); 126 128 clk->cl.con_id = con; 127 129 clk->cl.clk = clk;
+30 -16
arch/mips/lantiq/xway/sysctrl.c
··· 315 315 { 316 316 struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL); 317 317 318 + if (!clk) 319 + return; 318 320 clk->cl.dev_id = dev; 319 321 clk->cl.con_id = con; 320 322 clk->cl.clk = clk; ··· 340 338 { 341 339 struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL); 342 340 341 + if (!clk) 342 + return; 343 343 clk->cl.dev_id = dev; 344 344 clk->cl.con_id = con; 345 345 clk->cl.clk = clk; ··· 360 356 struct clk *clk_ext = kzalloc(sizeof(struct clk), GFP_KERNEL); 361 357 362 358 /* main pci clock */ 363 - clk->cl.dev_id = "17000000.pci"; 364 - clk->cl.con_id = NULL; 365 - clk->cl.clk = clk; 366 - clk->rate = CLOCK_33M; 367 - clk->rates = valid_pci_rates; 368 - clk->enable = pci_enable; 369 - clk->disable = pmu_disable; 370 - clk->module = 0; 371 - clk->bits = PMU_PCI; 372 - clkdev_add(&clk->cl); 359 + if (clk) { 360 + clk->cl.dev_id = "17000000.pci"; 361 + clk->cl.con_id = NULL; 362 + clk->cl.clk = clk; 363 + clk->rate = CLOCK_33M; 364 + clk->rates = valid_pci_rates; 365 + clk->enable = pci_enable; 366 + clk->disable = pmu_disable; 367 + clk->module = 0; 368 + clk->bits = PMU_PCI; 369 + clkdev_add(&clk->cl); 370 + } 373 371 374 372 /* use internal/external bus clock */ 375 - clk_ext->cl.dev_id = "17000000.pci"; 376 - clk_ext->cl.con_id = "external"; 377 - clk_ext->cl.clk = clk_ext; 378 - clk_ext->enable = pci_ext_enable; 379 - clk_ext->disable = pci_ext_disable; 380 - clkdev_add(&clk_ext->cl); 373 + if (clk_ext) { 374 + clk_ext->cl.dev_id = "17000000.pci"; 375 + clk_ext->cl.con_id = "external"; 376 + clk_ext->cl.clk = clk_ext; 377 + clk_ext->enable = pci_ext_enable; 378 + clk_ext->disable = pci_ext_disable; 379 + clkdev_add(&clk_ext->cl); 380 + } 381 381 } 382 382 383 383 /* xway socs can generate clocks on gpio pins */ ··· 401 393 char *name; 402 394 403 395 name = kzalloc(sizeof("clkout0"), GFP_KERNEL); 396 + if (!name) 397 + continue; 404 398 sprintf(name, "clkout%d", i); 405 399 406 400 clk = kzalloc(sizeof(struct clk), GFP_KERNEL); 401 + if (!clk) { 402 + kfree(name); 403 + continue; 404 + } 407 405 clk->cl.dev_id = "1f103000.cgu"; 408 406 clk->cl.con_id = name; 409 407 clk->cl.clk = clk;