From patchwork Fri Feb 12 17:43:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 61875 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp967568lbl; Fri, 12 Feb 2016 09:49:09 -0800 (PST) X-Received: by 10.98.64.132 with SMTP id f4mr3886798pfd.159.1455299349074; Fri, 12 Feb 2016 09:49:09 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r25si21242694pfi.85.2016.02.12.09.49.08; Fri, 12 Feb 2016 09:49:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750886AbcBLRs6 (ORCPT + 6 others); Fri, 12 Feb 2016 12:48:58 -0500 Received: from mail-lf0-f48.google.com ([209.85.215.48]:36705 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751959AbcBLRs5 (ORCPT ); Fri, 12 Feb 2016 12:48:57 -0500 Received: by mail-lf0-f48.google.com with SMTP id 78so56286088lfy.3 for ; Fri, 12 Feb 2016 09:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IVFgGZp1o1pxcAZbdYb3IdO1khoCPS/Y6/BYiGQeLoQ=; b=QKjIsSGlm8bxuoSvEopNtiEzTuiMjBJgGM4NtHDRoCSXh78KyyjyHq3ZThxhCrFnAq 6lwDgQ6k9m+tbbMwf8TKqAQrUYsI79PCD5Y+0DlVpobaUeKbMY3nGsNydnIAkNC0l2dY AnsgxICfK+8xpWjO9kQ5jjVjNR8FB9xoADYOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IVFgGZp1o1pxcAZbdYb3IdO1khoCPS/Y6/BYiGQeLoQ=; b=dkLTnHrNwIaeMGm8Cm996tkGBZJYc/duzeR23eBq2BxKwbQkyf1k4C1zCILfo1spCs ZVxtz3NS880oVvIzedbk16YkczkP8mS1P6KWORz1cg5cBTaiKOeDJV/+letN2yCt6GnP k4WxHYxrvRuQsCeI1rzUWpbpgijD54Wmft8npNcT/nb4Zrl6PyxpgNlE3gDBKhj08s0w v5bB8XOrvNeF0LSfCBQFEdZcAIy2shIzLcRKFwdHuC20lbKQaUKm63W9N0bpTKvV4+MF gU13JWrlH8fwmaW5kHnjkYKM6gn5gN/NlHA18wBluK+g0k7QBOxaeLg8XOpU5FMzFnzV 3yTQ== X-Gm-Message-State: AG10YOTlNCXOAxkgi2jeDheEzCgWP6QTrx33nVZSPbe5voekmqzRUvQXF0N1oNxWdAi4O8UK X-Received: by 10.25.148.208 with SMTP id w199mr1233346lfd.124.1455299335490; Fri, 12 Feb 2016 09:48:55 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id ei4sm2017549lbb.18.2016.02.12.09.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 09:48:54 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aleksey Makarov , Russell King , Greg Kroah-Hartman , "Rafael J . Wysocki" , Leif Lindholm , Graeme Gregory , Al Stone , Christopher Covington , Len Brown Subject: [PATCH v2 3/9] ACPI: introduce acpi_table_parse2() Date: Fri, 12 Feb 2016 20:43:34 +0300 Message-Id: <1455299022-11641-4-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455299022-11641-1-git-send-email-aleksey.makarov@linaro.org> References: <1455299022-11641-1-git-send-email-aleksey.makarov@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The function acpi_table_parse() has some problems: 1 It can be called only from __init code 2 It does not pass any data to the handler 3 It just throws out the value returned from the handler These issues are addressed in this patch Signed-off-by: Aleksey Makarov --- drivers/acpi/tables.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- include/linux/acpi.h | 8 ++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) -- 2.7.0 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 6c0f079..98ae052 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -40,7 +40,7 @@ static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" }; static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; -static int acpi_apic_instance __initdata; +static int acpi_apic_instance; /* * Disable table checksum verification for the early stage due to the size @@ -374,19 +374,27 @@ acpi_table_parse_madt(enum acpi_madt_type id, } /** - * acpi_table_parse - find table with @id, run @handler on it + * acpi_table_parse2 - find table with @id, run @handler on it * @id: table id to find * @handler: handler to run + * @data: data to pass to handler * * Scan the ACPI System Descriptor Table (STD) for a table matching @id, * run @handler on it. * - * Return 0 if table found, -errno if not. + * How it differs from acpi_table_parse() + * 1. It respect the return value of the handler function + * 2. It has additional data argument to make closures + * 3. It can be called from everywhere from the kernel (no __init) + * + * Return: the value returned by the handler if table found, -errno if not. */ -int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) +int acpi_table_parse2(char *id, + int (*handler)(struct acpi_table_header *table, void *data), void *data) { struct acpi_table_header *table = NULL; acpi_size tbl_size; + int err; if (acpi_disabled) return -ENODEV; @@ -395,16 +403,43 @@ int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) return -EINVAL; if (strncmp(id, ACPI_SIG_MADT, 4) == 0) - acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size); + acpi_get_table_with_size(id, acpi_apic_instance, &table, + &tbl_size); else acpi_get_table_with_size(id, 0, &table, &tbl_size); if (table) { - handler(table); + err = handler(table, data); early_acpi_os_unmap_memory(table, tbl_size); - return 0; + return err; } else return -ENODEV; + +} + +/* + * 1. fix the signature + * 2. always return 0, don't respect the value returned from the handler + */ +static int legacy_acpi_table_handler(struct acpi_table_header *table, void *d) +{ + ((acpi_tbl_table_handler)d)(table); + return 0; +} + +/** + * acpi_table_parse - find table with @id, run @handler on it + * @id: table id to find + * @handler: handler to run + * + * Scan the ACPI System Descriptor Table (STD) for a table matching @id, + * run @handler on it. + * + * Return 0 if table found, -errno if not. + */ +int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) +{ + return acpi_table_parse2(id, legacy_acpi_table_handler, handler); } /* diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..bed9b89 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -218,6 +218,8 @@ int acpi_numa_init (void); int acpi_table_init (void); int acpi_table_parse(char *id, acpi_tbl_table_handler handler); +int acpi_table_parse2(char *id, int (*handler)(struct acpi_table_header *table, + void *data), void *data); int __init acpi_parse_entries(char *id, unsigned long table_size, acpi_tbl_entry_handler handler, struct acpi_table_header *table_header, @@ -636,6 +638,12 @@ static inline int acpi_table_parse(char *id, return -ENODEV; } +int acpi_table_parse2(char *id, int (*handler)(struct acpi_table_header *table, + void *data), void *data) +{ + return -ENODEV; +} + static inline int acpi_nvs_register(__u64 start, __u64 size) { return 0;