public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Len Brown <lenb@kernel.org>
Cc: x86@kernel.org, sfi-devel@simplefirmware.org,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	Feng Tang <feng.tang@intel.com>, Len Brown <len.brown@intel.com>
Subject: Re: [PATCH 09/12] SFI: Enable SFI to parse ACPI tables
Date: Fri, 10 Jul 2009 08:10:51 +0200	[thread overview]
Message-ID: <20090710061051.GE22218@elte.hu> (raw)
In-Reply-To: <5ab9dd34acc6209c5b6a3c754075e408e5298a2d.1247025117.git.len.brown@intel.com>


* Len Brown <lenb@kernel.org> wrote:

> From: Feng Tang <feng.tang@intel.com>

> +++ b/drivers/sfi/sfi_acpi.c

> +static struct acpi_table_xsdt *xsdt_va;

Should be __read_mostly.

> +static struct acpi_table_header *sfi_acpi_get_table(char *signature,
> +			char *oem_id, char *oem_table_id, unsigned int flags)
> +{
> +	struct acpi_table_header *th;
> +	u32 tbl_cnt, i;
> +	u64 pa;
> +
> +	tbl_cnt = XSDT_GET_NUM_ENTRIES(xsdt_va, u64);
> +
> +	for (i = 0; i < tbl_cnt; i++) {
> +		pa = xsdt_va->table_offset_entry[i];
> +
> +		th = (struct acpi_table_header *)sfi_map_table(pa);
> +		if (!th)
> +			return NULL;
> +
> +		if (strncmp(th->signature, signature, SFI_SIGNATURE_SIZE))
> +			goto loop_continue;
> +
> +		if (oem_id && strncmp(th->oem_id, oem_id, SFI_OEM_ID_SIZE))
> +			goto loop_continue;
> +
> +		if (oem_table_id && strncmp(th->oem_table_id, oem_table_id,
> +						SFI_OEM_TABLE_ID_SIZE))
> +			goto loop_continue;
> +
> +		return th;      /* success */
> +loop_continue:
> +		sfi_unmap_table((struct sfi_table_header *)th);
> +	}
> +
> +	return NULL;

That loop looks weird and non-standard.

The body should be factored out into a check_table(th) helper 
function, and the loop can thus be written as a very straightforward 
one:

	th = NULL;

	for (i = 0; i < tbl_cnt; i++) {
		pa = xsdt_va->table_offset_entry[i];

		th = check_table(pa, signature, oem_id, oem_table_id))
		if (IS_ERR(th))
			return NULL;
		if (th)
			return th;
	}

	return th;

where check_table() returns PTR_ERR(-EINVAL) on mapping failure, 
NULL on mismatch and a table header on match.

Also, a general comment for the whole series: the various type casts 
between ACPI and SFI table headers look ugly and are a bit fragile. 
It would be better to define explicit type conversion helper inlines 
between ACPI an SFI types - and those would thus be type-safe. 
(right now it's easy to typo a variable name and pass in something 
that is neither an ACPI nor an SFI header.)

So we should have two primitives:

	acpi_to_sfi_table(table)
	sfi_to_acpi_table(table)

> +static void sfi_acpi_put_table(struct acpi_table_header *table)
> +{
> +	sfi_put_table((struct sfi_table_header *)table);
> +}

the above could thus be written as:

static void sfi_acpi_put_table(struct acpi_table_header *table)
{
	sfi_put_table(acpi_to_sfi_table(table));
}

> +/*
> + * sfi_acpi_table_parse()
> + *
> + * find specified table in XSDT, run handler on it and return its return value
> + */
> +int sfi_acpi_table_parse(char *signature, char *oem_id, char *oem_table_id,
> +		 unsigned int flags, int(*handler)(struct acpi_table_header *))
> +{

i'd suggest to define a helper structure for the 'table key' fields 
above. They get passed around repetitively. Also, a 
acpi_handler_fn_t helper would be useful as well. That way the above 
prototype could be written as:

int sfi_acpi_table_parse(struct acpi_table_key key, unsigned int flags,
                         acpi_handler_fn_t *handler);

which is a lot more readable and 'key' could be passed straight to 
the sfi parser.

> +++ b/include/linux/sfi_acpi.h

> +#ifdef	CONFIG_SFI

Small nit: we dont generally put tabs into ifdefs, unless strongly 
warranted (which this one does not seem to be).

	Ingo

  reply	other threads:[~2009-07-10  6:11 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-08  4:13 [PATCH v2 for 2.6.32] SFI - Simple Firmware Interface support Len Brown
2009-07-08  4:13 ` [PATCH 01/12] SFI: Simple Firmware Interface - new MAINTAINERS entry Len Brown
2009-07-08  4:13   ` [PATCH 02/12] SFI, x86: add CONFIG_SFI Len Brown
2009-07-10  5:23     ` Ingo Molnar
2009-07-08  4:13   ` [PATCH 03/12] SFI: document boot param "sfi=off" Len Brown
2009-07-28 19:24     ` Bjorn Helgaas
2009-07-28 19:52       ` Len Brown
2009-07-08  4:13   ` [PATCH 04/12] SFI: create include/linux/sfi.h Len Brown
2009-07-10  6:48     ` Ingo Molnar
2009-07-08  4:13   ` [PATCH 05/12] SFI: add core support Len Brown
2009-07-10  7:40     ` Ingo Molnar
2009-07-08  4:13   ` [PATCH 06/12] ACPI, x86: remove ACPI dependency on some IO-APIC routines Len Brown
2009-07-10  6:51     ` Ingo Molnar
2009-07-08  4:13   ` [PATCH 07/12] SFI: add x86 support Len Brown
2009-07-10  6:37     ` Ingo Molnar
2009-07-10  6:48       ` Feng Tang
2009-07-08  4:13   ` [PATCH 08/12] SFI, x86: hook e820() for memory map initialization Len Brown
2009-07-08 21:37     ` H. Peter Anvin
2009-07-09  1:11       ` Feng Tang
2009-07-09  3:57         ` H. Peter Anvin
2009-07-08  4:13   ` [PATCH 09/12] SFI: Enable SFI to parse ACPI tables Len Brown
2009-07-10  6:10     ` Ingo Molnar [this message]
2009-07-08  4:13   ` [PATCH 10/12] ACPI: check acpi_disabled in acpi_table_parse() Len Brown
2009-07-08  4:13   ` [PATCH 11/12] SFI, PCI: Hook MMCONFIG Len Brown
2009-07-10  5:52     ` Ingo Molnar
2009-07-10  7:17       ` Feng Tang
2009-07-10 11:14         ` Ingo Molnar
2009-07-08  4:13   ` [PATCH 12/12] SFI: add boot-time initialization hooks Len Brown
2009-07-10  5:18 ` [PATCH v2 for 2.6.32] SFI - Simple Firmware Interface support Ingo Molnar
2009-07-11  1:01   ` Len Brown
2009-07-11  8:26     ` Ingo Molnar

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=20090710061051.GE22218@elte.hu \
    --to=mingo@elte.hu \
    --cc=feng.tang@intel.com \
    --cc=len.brown@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sfi-devel@simplefirmware.org \
    --cc=x86@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