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

macintosh/windfarm_pm121.c: Fix for possible null pointer dereference

There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Rickard Strandqvist and committed by
Benjamin Herrenschmidt
bd0c30e3 1efc5638

+13 -3
+13 -3
drivers/macintosh/windfarm_pm121.c
··· 555 555 pid_param.interval = PM121_SYS_INTERVAL; 556 556 pid_param.history_len = PM121_SYS_HISTORY_SIZE; 557 557 pid_param.itarget = param->itarget; 558 - pid_param.min = control->ops->get_min(control); 559 - pid_param.max = control->ops->get_max(control); 558 + if(control) 559 + { 560 + pid_param.min = control->ops->get_min(control); 561 + pid_param.max = control->ops->get_max(control); 562 + } else { 563 + /* 564 + * This is probably not the right!? 565 + * Perhaps goto fail if control == NULL above? 566 + */ 567 + pid_param.min = 0; 568 + pid_param.max = 0; 569 + } 560 570 561 571 wf_pid_init(&pm121_sys_state[loop_id]->pid, &pid_param); 562 572 ··· 581 571 control the same control */ 582 572 printk(KERN_WARNING "pm121: failed to set up %s loop " 583 573 "setting \"%s\" to max speed.\n", 584 - loop_names[loop_id], control->name); 574 + loop_names[loop_id], control ? control->name : "uninitialized value"); 585 575 586 576 if (control) 587 577 wf_control_set_max(control);