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

spmi: Return meaningful errors in spmi_controller_alloc()

spmi_controller_alloc() currently returns NULL to all types of errors,
which can be improved.

Use appropriate error code in returns and pass the errors from used
functions where possible.

Signed-off-by: Fei Shao <fshao@chromium.org>
Link: https://lore.kernel.org/r/20230824104101.4083400-6-fshao@chromium.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20231206231733.4031901-8-sboyd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Fei Shao and committed by
Greg Kroah-Hartman
3ae3cf41 490d88ef

+5 -5
+2 -2
drivers/spmi/spmi-devres.c
··· 20 20 return ERR_PTR(-ENOMEM); 21 21 22 22 ctrl = spmi_controller_alloc(parent, size); 23 - if (!ctrl) { 23 + if (IS_ERR(ctrl)) { 24 24 devres_free(ptr); 25 - return ERR_PTR(-ENOMEM); 25 + return ctrl; 26 26 } 27 27 28 28 *ptr = ctrl;
+3 -3
drivers/spmi/spmi.c
··· 448 448 int id; 449 449 450 450 if (WARN_ON(!parent)) 451 - return NULL; 451 + return ERR_PTR(-EINVAL); 452 452 453 453 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); 454 454 if (!ctrl) 455 - return NULL; 455 + return ERR_PTR(-ENOMEM); 456 456 457 457 device_initialize(&ctrl->dev); 458 458 ctrl->dev.type = &spmi_ctrl_type; ··· 466 466 dev_err(parent, 467 467 "unable to allocate SPMI controller identifier.\n"); 468 468 spmi_controller_put(ctrl); 469 - return NULL; 469 + return ERR_PTR(id); 470 470 } 471 471 472 472 ctrl->nr = id;