public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Stuart_Hayes@dell.com
Cc: linux-acpi@vger.kernel.org, mjg@redhat.com, Rezwanul_Kabir@dell.com
Subject: Re: [PATCH] dell-laptop: Use buffer with 32-bit physical address
Date: Thu, 22 Oct 2009 09:12:16 -0600	[thread overview]
Message-ID: <200910220912.17684.bjorn.helgaas@hp.com> (raw)
In-Reply-To: <DFEF91B22ED07447AB6AA4B237F913F9039D0A64@ausx3mpc125.aus.amer.dell.com>

On Wednesday 21 October 2009 01:04:09 pm Stuart_Hayes@dell.com wrote:
> 
> Calls to communicate with system firmware via a SMI (using dcdbas) need
> to use a buffer that has a physical address of 4GB or less.  Currently
> the dell-laptop driver does not guarantee this, and when the buffer
> address is higher than 4GB, the address is truncated to 32 bits and the
> SMI handler writes to the wrong memory address.
> 
> Signed-off-by: Stuart Hayes <stuart_hayes@dell.com>

+static void get_buffer(void)
+{
+	mutex_lock(&buffer_mutex);
+	memset(buffer, 0, sizeof(struct calling_interface_buffer));
+}
+
+static void release_buffer(void)
+{
+	mutex_unlock(&buffer_mutex);
+}


 static int dell_rfkill_set(void *data, bool blocked)
 {
-	struct calling_interface_buffer buffer;
 	int disable = blocked ? 1 : 0;
 	unsigned long radio = (unsigned long)data;
 
 	printk(KERN_WARNING "MATCH, disable is %d\n", disable);
 	printk(KERN_WARNING "MATCH, radio is %x\n", radio);
 
-	memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-	buffer.input[0] = (1 | (radio<<8) | (disable << 16));
-	dell_send_request(&buffer, 17, 11);
+	get_buffer();
+	buffer->input[0] = (1 | (radio<<8) | (disable << 16));
+	dell_send_request(buffer, 17, 11);
+	release_buffer();


I think it would be slightly nicer to do something like this:

    static struct calling_interface_buffer *get_buffer(void);

    static int dell_rfkill_set(void *data, bool blocked)
    {
	struct calling_interface_buffer *buffer;

	buffer = get_buffer();
	...
	release_buffer(buffer);
    }

    static struct calling_interface_buffer *buffer;
    DEFINE_MUTEX(buffer_mutex);

    static struct calling_interface_buffer *get_buffer(void)
    {
	mutex_lock(&buffer_mutex);
	memset(buffer, 0, sizeof(struct calling_interface_buffer));
	return buffer;
    }

because it makes it a little harder to mistakenly use the global
buffer without acquiring the mutex.  With a little work, the
global buffer could probably even be made static to get_buffer(),
to make it *impossible* to get the pointer outside the mutex.

Bjorn

  parent reply	other threads:[~2009-10-22 15:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21 19:04 [PATCH] dell-laptop: Use buffer with 32-bit physical address Stuart_Hayes
2009-10-22  1:57 ` Matthew Garrett
2009-10-22 16:27   ` Stuart_Hayes
2009-10-22 15:12 ` Bjorn Helgaas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-02-04 22:56 Matthew Garrett
2010-02-06 15:38 ` Henrique de Moraes Holschuh

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=200910220912.17684.bjorn.helgaas@hp.com \
    --to=bjorn.helgaas@hp.com \
    --cc=Rezwanul_Kabir@dell.com \
    --cc=Stuart_Hayes@dell.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mjg@redhat.com \
    /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