public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vernon Mauery <vernux@us.ibm.com>
To: Greg KH <gregkh@us.ibm.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Pat Gaughen <gone@us.ibm.com>, Chris McDermott <lcm@us.ibm.com>,
	Jess Botts <botts@us.ibm.com>
Subject: Re: [PATCH] acpiphp extension for 2.6.7
Date: Fri, 25 Jun 2004 09:42:58 -0700	[thread overview]
Message-ID: <1088181777.4749.11.camel@bluerat> (raw)
In-Reply-To: <20040624214555.GA1800@us.ibm.com>

On Thu, 2004-06-24 at 14:45, Greg KH wrote: 
> > +int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
> > +{
> > +	int retval = 0;
> > +	unsigned long flags;
> > +
> > +	if (!info || !info->owner || !info->set_attn || !info->get_attn)
> > +		retval = -1;
> > +	else {
> > +		spin_lock_irqsave(&attn_info_lock, flags);
> 
> Why lock here?  What could race?

If this function is only ever called from a module's init_module
function, then our global data is protected by the kernel's
module_mutex.  But is the assumption that it is never called from other
code safe to make?  It manipulates global data, so it needs to be
protected somehow...

> And why the irqsave lock?
Not sure.  That can be changed.

> > -static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
> > +static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
> >  {
> > +	int retval = -1;
> > +	unsigned long flags;
> > +	struct acpiphp_attention_info info;
> > +
> >  	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
> >  
> > -	switch (status) {
> > -		case 0:
> > -			/* FIXME turn light off */
> > -			hotplug_slot->info->attention_status = 0;
> > -			break;
> > -
> > -		case 1:
> > -		default:
> > -			/* FIXME turn light on */
> > -			hotplug_slot->info->attention_status = 1;
> > -			break;
> > +	spin_lock_irqsave(&attn_info_lock, flags);
> > +	memcpy(&info, &attention_info, sizeof(struct acpiphp_attention_info));
> > +	spin_unlock_irqrestore(&attn_info_lock, flags);
> 
> Again, why lock?  And why copy the whole structure?  And it's on the
> stack, which isn't very nice.  Same comment applies to the get_
> function.

Getting a local copy of the data structure within the lock ensures that
this function is reentrant.  But if we can make the same guarantee that
this funtion is called only on module_exit (again protected by the
module_mutex) then we can move to a pointer and no local lock.

> > +
> > +	if (info.set_attn && try_module_get(info.owner)) {
> > +		retval = info.set_attn(hotplug_slot, status);
> > +		module_put(info.owner);
> >  	}
> >  
> > -	return 0;
> > +	if (!retval)
> > +		hotplug_slot->info->attention_status = (status) ? 1 : 0;
> 
> Why change the value based on the return value of the call?  This
> shouldn't be set at all.

Oops.  This was a snippet of legacy code that was around before I
figured out how to read the LED value from hardware.  I will drop it.

--Vernon



  reply	other threads:[~2004-06-25 16:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 19:53 [PATCH] acpiphp extension for 2.6.7 Vernon Mauery
2004-06-24 21:45 ` Greg KH
2004-06-25 16:42   ` Vernon Mauery [this message]
2004-06-29 18:47   ` Vernon Mauery
2004-06-29 23:50   ` [PATCH] [0/2] " Vernon Mauery
2004-07-02 20:58     ` [Pcihpd-discuss] " Greg KH
2004-07-03  0:02       ` [PATCH] [0/2] acpiphp extension for 2.6.7 (take 3) Vernon Mauery
2004-07-03  0:02       ` [PATCH] [1/2] " Vernon Mauery
2004-07-03  0:02       ` [PATCH] [2/2] " Vernon Mauery
2004-06-29 23:50   ` [PATCH] [1/2] acpiphp extension for 2.6.7 Vernon Mauery
2004-06-29 23:50   ` [PATCH] [2/2] " Vernon Mauery
     [not found] ` <200407071147.57604@bilbo.math.uni-mannheim.de>
     [not found]   ` <1089216410.24908.5.camel@bluerat>
     [not found]     ` <200407081209.42927@bilbo.math.uni-mannheim.de>
     [not found]       ` <1089328415.2089.194.camel@bluerat>
     [not found]         ` <20040708232827.GA20755@kroah.com>
2004-07-09  0:11           ` [PATCH] [0/2] acpiphp extension for 2.6.7 (final) Vernon Mauery
2004-07-09  0:12           ` [PATCH] [1/2] " Vernon Mauery
2004-07-14 22:52             ` Greg KH
2004-07-09  0:12           ` [PATCH] [2/2] " Vernon Mauery
2004-07-14 22:52             ` Greg KH
2004-09-16 18:23           ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
2004-09-17 22:10             ` Vernon Mauery
2004-09-22 20:29               ` Greg KH

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=1088181777.4749.11.camel@bluerat \
    --to=vernux@us.ibm.com \
    --cc=botts@us.ibm.com \
    --cc=gone@us.ibm.com \
    --cc=gregkh@us.ibm.com \
    --cc=lcm@us.ibm.com \
    --cc=linux-kernel@vger.kernel.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