Re: [PATCH] oprofile, x86: fix init_sysfs error handling

From: Ingo Molnar
Date: Wed Sep 01 2010 - 05:51:35 EST



* Robert Richter <robert.richter@xxxxxxx> wrote:

> On 31.08.10 05:31:29, Will Deacon wrote:
> > > For x86 wont change the code (actually I found a bug in the init_sysfs
> > > error handler for which I will send a fix). Just wanted to get your
> > > confirmation in case I was missing something that x86 is not affected.
> > > I will apply the first 2 patches, no need to resubmit.
>
> This is the patch, applied to:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git urgent
>
> -Robert
>
> --
>
> >From 10f0412f57f2a76a90eff4376f59cbb0a39e4e18 Mon Sep 17 00:00:00 2001
> From: Robert Richter <robert.richter@xxxxxxx>
> Date: Mon, 30 Aug 2010 10:56:18 +0200
> Subject: [PATCH] oprofile, x86: fix init_sysfs error handling
>
> On failure init_sysfs() might not properly free resources. The error
> code of the function is not checked. And, when reinitializing the exit
> function might be called twice. This patch fixes all this.
>
> Cc: stable@xxxxxxxxxx
> Signed-off-by: Robert Richter <robert.richter@xxxxxxx>
> ---
> arch/x86/oprofile/nmi_int.c | 16 +++++++++++++---
> 1 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
> index f6b48f6..73a41d3 100644
> --- a/arch/x86/oprofile/nmi_int.c
> +++ b/arch/x86/oprofile/nmi_int.c
> @@ -568,8 +568,13 @@ static int __init init_sysfs(void)
> int error;
>
> error = sysdev_class_register(&oprofile_sysclass);
> - if (!error)
> - error = sysdev_register(&device_oprofile);
> + if (error)
> + return error;
> +
> + error = sysdev_register(&device_oprofile);
> + if (error)
> + sysdev_class_unregister(&oprofile_sysclass);
> +
> return error;
> }
>
> @@ -695,6 +700,8 @@ int __init op_nmi_init(struct oprofile_operations *ops)
> char *cpu_type = NULL;
> int ret = 0;
>
> + using_nmi = 0;
> +
> if (!cpu_has_apic)
> return -ENODEV;
>
> @@ -774,7 +781,10 @@ int __init op_nmi_init(struct oprofile_operations *ops)
>
> mux_init(ops);
>
> - init_sysfs();
> + ret = init_sysfs();

FYI, this causes a build error if CONFIG_PM is off:

arch/x86/oprofile/nmi_int.c:784: error: expected expression before âdoâ

Due to this assymetric form of the wrapper:

#define init_sysfs() do { } while (0)

The wrapper should be changed to return 0 i suspect, via something like
this:

static inline int init_sysfs(void) { return 0; }

(untested)

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/