Skip to content

Commit 73f38fe

Browse files
Julia Lawallpaulusmack
authored andcommitted
drivers/macintosh/smu.c: Improve error handling
This makes two changes: * As noted by Akinobu Mita in patch b1fceac, alloc_bootmem never returns NULL and always returns a zeroed region of memory. Thus the error checking code and memset after the call to alloc_bootmem are not necessary. * The old error handling code consisted of setting a global variable to NULL and returning an error code, which could cause previously allocated resources never to be freed. The patch adds calls to appropriate resource deallocation functions. Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 178f8d7 commit 73f38fe

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

‎drivers/macintosh/smu.c‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ int __init smu_init (void)
474474
{
475475
struct device_node *np;
476476
const u32 *data;
477+
int ret = 0;
477478

478479
np = of_find_node_by_type(NULL, "smu");
479480
if (np == NULL)
@@ -483,16 +484,11 @@ int __init smu_init (void)
483484

484485
if (smu_cmdbuf_abs == 0) {
485486
printk(KERN_ERR "SMU: Command buffer not allocated !\n");
486-
of_node_put(np);
487-
return -EINVAL;
487+
ret = -EINVAL;
488+
goto fail_np;
488489
}
489490

490491
smu = alloc_bootmem(sizeof(struct smu_device));
491-
if (smu == NULL) {
492-
of_node_put(np);
493-
return -ENOMEM;
494-
}
495-
memset(smu, 0, sizeof(*smu));
496492

497493
spin_lock_init(&smu->lock);
498494
INIT_LIST_HEAD(&smu->cmd_list);
@@ -510,14 +506,14 @@ int __init smu_init (void)
510506
smu->db_node = of_find_node_by_name(NULL, "smu-doorbell");
511507
if (smu->db_node == NULL) {
512508
printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n");
513-
goto fail;
509+
ret = -ENXIO;
510+
goto fail_bootmem;
514511
}
515512
data = of_get_property(smu->db_node, "reg", NULL);
516513
if (data == NULL) {
517-
of_node_put(smu->db_node);
518-
smu->db_node = NULL;
519514
printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n");
520-
goto fail;
515+
ret = -ENXIO;
516+
goto fail_db_node;
521517
}
522518

523519
/* Current setup has one doorbell GPIO that does both doorbell
@@ -551,7 +547,8 @@ int __init smu_init (void)
551547
smu->db_buf = ioremap(0x8000860c, 0x1000);
552548
if (smu->db_buf == NULL) {
553549
printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n");
554-
goto fail;
550+
ret = -ENXIO;
551+
goto fail_msg_node;
555552
}
556553

557554
/* U3 has an issue with NAP mode when issuing SMU commands */
@@ -562,10 +559,17 @@ int __init smu_init (void)
562559
sys_ctrler = SYS_CTRLER_SMU;
563560
return 0;
564561

565-
fail:
562+
fail_msg_node:
563+
if (smu->msg_node)
564+
of_node_put(smu->msg_node);
565+
fail_db_node:
566+
of_node_put(smu->db_node);
567+
fail_bootmem:
568+
free_bootmem((unsigned long)smu, sizeof(struct smu_device));
566569
smu = NULL;
567-
return -ENXIO;
568-
570+
fail_np:
571+
of_node_put(np);
572+
return ret;
569573
}
570574

571575

0 commit comments

Comments
 (0)