linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Sergei Trofimovich <slyich@gmail.com>,
	linux-kernel@vger.kernel.org, Kay Sievers <kay.sievers@vrfy.org>,
	Linux PM mailing list <linux-pm@vger.kernel.org>,
	Tony Luck <tony.luck@intel.com>, "mingo@elte.hu" <mingo@elte.hu>,
	Borislav Petkov <bp@amd64.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	prasad@linux.vnet.ibm.com, Ming Lei <tom.leiming@gmail.com>,
	Djalal Harouni <tixxdz@opendz.org>,
	Borislav Petkov <borislav.petkov@amd.com>,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Andi Kleen <ak@linux.intel.com>,
	gouders@et.bocholt.fh-gelsenkirchen.de,
	Marcos Souza <marcos.mage@gmail.com>,
	justinmattock@gmail.com, Jeff Chua <jeff.chua.linux@gmail.com>,
	neilb@suse.de
Subject: Re: [PATCH] mce: fix warning messages about static struct mce_device
Date: Tue, 17 Jan 2012 07:52:10 -0800	[thread overview]
Message-ID: <20120117155210.GC13778@suse.de> (raw)
In-Reply-To: <4F156B53.9020008@linux.vnet.ibm.com>

On Tue, Jan 17, 2012 at 06:06:35PM +0530, Srivatsa S. Bhat wrote:
> On 01/17/2012 04:10 AM, Greg KH wrote:
> 
> > From: Greg Kroah-Hartman <gregkh@suse.de>
> > 
> > When suspending, there was a large list of warnings going something like:
> > 
> > 	Device 'machinecheck1' does not have a release() function, it is broken and must be fixed
> > 
> > This patch turns the static mce_devices into dynamically allocated, and
> > properly frees them when they are removed from the system.  It solves
> > the warning messages on my laptop here.
> >
> 
> ...
> 
> >  /* Per cpu device init. All of the cpus still share the same ctrl bank: */
> >  static __cpuinit int mce_device_create(unsigned int cpu)
> >  {
> > -	struct device *dev = &per_cpu(mce_device, cpu);
> > +	struct device *dev;
> >  	int err;
> >  	int i, j;
> > 
> >  	if (!mce_available(&boot_cpu_data))
> >  		return -EIO;
> > 
> > -	memset(dev, 0, sizeof(struct device));
> > +	dev = kzalloc(sizeof *dev, GFP_KERNEL);
> > +	if (!dev)
> > +		return -ENOMEM;
> >  	dev->id  = cpu;
> >  	dev->bus = &mce_subsys;
> > +	dev->release = &mce_device_release;
> > 
> >  	err = device_register(dev);
> >  	if (err)
> > @@ -2030,6 +2038,7 @@ static __cpuinit int mce_device_create(unsigned int cpu)
> >  			goto error2;
> >  	}
> >  	cpumask_set_cpu(cpu, mce_device_initialized);
> > +	mce_device[cpu] = dev;
> > 
> >  	return 0;
> >  error2:
> > @@ -2046,7 +2055,7 @@ error:
> > 
> >  /* Make sure there are no machine checks on offlined CPUs. */
> > diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> > index ba0b94a..786e76a 100644
> > --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
> > +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> > @@ -523,6 +523,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
> >  {
> >  	int i, err = 0;
> >  	struct threshold_bank *b = NULL;
> > +	struct device *dev = mce_device[cpu];
> >  	char name[32];
> > 
> >  	sprintf(name, "threshold_bank%i", bank);
> > @@ -543,8 +544,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
> >  		if (!b)
> >  			goto out;
> > 
> > -		err = sysfs_create_link(&per_cpu(mce_device, cpu).kobj,
> > -					b->kobj, name);
> > +		err = sysfs_create_link(&dev->kobj, b->kobj, name);
> 
> 
> I don't think dereferencing 'dev' like this is safe when booting up.
> (See below for another such instance of dereferencing dev.)
> 
> Both mcheck_init_device() and threshold_init_device() are device_initcalls.
> And the latter depends on the former, because the former dynamically
> allocates and fills the 'mce_device' array of pointers.
> 
> So, what guarantees that this ordering is preserved? IOW, what ensures that
> mcheck_init_device() is completed before running threshold_init_device()?
> 
> Or am I missing something?

You must be, as this is the way it is always works, and somehow your
machine boots properly, with the symlinks setup :)

thanks,

greg k-h

      reply	other threads:[~2012-01-17 15:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-16 22:40 [PATCH] mce: fix warning messages about static struct mce_device Greg KH
2012-01-17  0:14 ` Djalal Harouni
2012-01-17  0:15   ` Greg KH
2012-01-17  0:21     ` Linus Torvalds
2012-01-17  1:00       ` Greg KH
2012-01-17  8:38 ` Ingo Molnar
2012-01-17 15:51   ` Greg KH
2012-01-17 16:28     ` Greg KH
2012-01-18  9:31     ` Ingo Molnar
2012-01-18 14:42       ` Greg KH
2012-01-18 15:51         ` Alan Stern
2012-01-18 17:28           ` Luck, Tony
2012-01-18 17:54             ` Srivatsa S. Bhat
2012-01-18 18:10             ` Alan Stern
2012-01-18 18:50               ` Kay Sievers
2012-01-18 19:00                 ` Luck, Tony
2012-01-18 19:31                 ` Srivatsa S. Bhat
2012-01-19 12:32                 ` Ingo Molnar
2012-01-19 13:29                   ` Srivatsa S. Bhat
2012-01-19 15:13                     ` Alan Stern
2012-01-19 19:38                       ` Ingo Molnar
2012-01-19 20:52                         ` Alan Stern
2012-01-19 12:28         ` Ingo Molnar
2012-01-26 23:49           ` MCE: convert static array of pointers to per-cpu variables Greg KH
2012-01-27 13:14             ` Srivatsa S. Bhat
2012-01-17 12:36 ` [PATCH] mce: fix warning messages about static struct mce_device Srivatsa S. Bhat
2012-01-17 15:52   ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120117155210.GC13778@suse.de \
    --to=gregkh@suse.de \
    --cc=ak@linux.intel.com \
    --cc=borislav.petkov@amd.com \
    --cc=bp@amd64.org \
    --cc=gouders@et.bocholt.fh-gelsenkirchen.de \
    --cc=jeff.chua.linux@gmail.com \
    --cc=justinmattock@gmail.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=marcos.mage@gmail.com \
    --cc=mingo@elte.hu \
    --cc=neilb@suse.de \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rjw@sisk.pl \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=slyich@gmail.com \
    --cc=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=tixxdz@opendz.org \
    --cc=tom.leiming@gmail.com \
    --cc=tony.luck@intel.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).