提交 f61fb8a5 编写于 作者: N Nathan Lynch 提交者: Paul Mackerras

[POWERPC] scanlog_init cleanup and minor fixes

scanlog_init() could use some love.

* properly return -ENODEV if this system doesn't support scan-log-dump
* don't printk if scan-log-dump not present; only older systems have it
* convert from create_proc_entry() to preferred proc_create()
* allocate zeroed data buffer
* fix potential memory leak of ent->data on failed create_proc_entry()
* simplify control flow
Signed-off-by: NNathan Lynch <ntl@pobox.com>
Signed-off-by: NPaul Mackerras <paulus@samba.org>
上级 9356d90e
...@@ -195,31 +195,30 @@ const struct file_operations scanlog_fops = { ...@@ -195,31 +195,30 @@ const struct file_operations scanlog_fops = {
static int __init scanlog_init(void) static int __init scanlog_init(void)
{ {
struct proc_dir_entry *ent; struct proc_dir_entry *ent;
void *data;
int err = -ENOMEM;
ibm_scan_log_dump = rtas_token("ibm,scan-log-dump"); ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE) { if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE)
printk(KERN_ERR "scan-log-dump not implemented on this system\n"); return -ENODEV;
return -EIO;
}
ent = create_proc_entry("ppc64/rtas/scan-log-dump", S_IRUSR, NULL); /* Ideally we could allocate a buffer < 4G */
if (ent) { data = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
ent->proc_fops = &scanlog_fops; if (!data)
/* Ideally we could allocate a buffer < 4G */ goto err;
ent->data = kmalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
if (!ent->data) { ent = proc_create("ppc64/rtas/scan-log-dump", S_IRUSR, NULL,
printk(KERN_ERR "Failed to allocate a buffer\n"); &scanlog_fops);
remove_proc_entry("scan-log-dump", ent->parent); if (!ent)
return -ENOMEM; goto err;
}
((unsigned int *)ent->data)[0] = 0; ent->data = data;
} else {
printk(KERN_ERR "Failed to create ppc64/scan-log-dump proc entry\n");
return -EIO;
}
proc_ppc64_scan_log_dump = ent; proc_ppc64_scan_log_dump = ent;
return 0; return 0;
err:
kfree(data);
return err;
} }
static void __exit scanlog_cleanup(void) static void __exit scanlog_cleanup(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册