From patchwork Mon Sep 30 03:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Zengkai X-Patchwork-Id: 13815339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8228FCF6498 for ; Mon, 30 Sep 2024 02:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=b84Zkxjeu1/7K0HQjNGAI/rK+biM4QmdkgXZxjbj77M=; b=C3ZdBvxUhS05g41rmuUVd872EI nNkJntTrama9J8tDmzDBA0OjsP8JE2AKg7Zpd6ymrRG6NC1A7iUg1ePa7HLFi9kOutMDavvjRIUj2 2VjLDTklAQbXncHnZllHgoSizr5z8olvK8k8wmYLXKy7zn3GtkbMVTjGcBKbCJPC93N/eYe0nY1UP xUIoyjXRXlvK7l0NAmHhgHVC7SuyWXkefoiWg6OfSkK+FAG41nPL3BYjiY0y8cnXPWUwJkR6RC0kP 4TZJO1iggVV/YxpfAhb9DoO313aIsUt3xXCG21MruMwn9AbRZ7Y9vSL7Lldo+Cx/11njEHk3A0HaW jLhpCdbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sv6V7-0000000FlZ2-2RVt; Mon, 30 Sep 2024 02:51:05 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sv6Tu-0000000FlTi-0dOA for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 02:49:52 +0000 Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XH5Bk6wDgz1ymhS; Mon, 30 Sep 2024 10:49:34 +0800 (CST) Received: from kwepemd200010.china.huawei.com (unknown [7.221.188.124]) by mail.maildlp.com (Postfix) with ESMTPS id 604161400CA; Mon, 30 Sep 2024 10:49:32 +0800 (CST) Received: from huawei.com (10.175.113.25) by kwepemd200010.china.huawei.com (7.221.188.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 30 Sep 2024 10:49:31 +0800 From: Zheng Zengkai To: , , , , , , CC: , , , , , Subject: [PATCH] ACPI: GTDT: simplify acpi_gtdt_init() implementation Date: Mon, 30 Sep 2024 11:07:16 +0800 Message-ID: <20240930030716.179992-1-zhengzengkai@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd200010.china.huawei.com (7.221.188.124) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240929_194951_340980_CD038E4E X-CRM114-Status: GOOD ( 18.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org According to GTDT Table Structure of ACPI specification, the result of expression '(void *)gtdt + gtdt->platform_timer_offset' will be same with the expression '(void *)table + sizeof(struct acpi_table_gtdt)' in function acpi_gtdt_init(), so the condition of the "invalid timer data" check will never be true, remove the EINVAL error check branch and change to void return type for acpi_gtdt_init() to simplify the function implementation and error handling by callers. Besides, after commit c2743a36765d ("clocksource: arm_arch_timer: add GTDT support for memory-mapped timer"), acpi_gtdt_init() currently will not be called with parameter platform_timer_count set to NULL and we can explicitly initialize the integer variable which is used for storing the number of platform timers by caller to zero, so there is no need to do null pointer check for platform_timer_count in acpi_gtdt_init(), remove it to make code a bit more concise. Signed-off-by: Zheng Zengkai --- drivers/acpi/arm64/gtdt.c | 31 +++++++--------------------- drivers/clocksource/arm_arch_timer.c | 6 ++---- include/linux/acpi.h | 2 +- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c index c0e77c1c8e09..b6d248ddb1b3 100644 --- a/drivers/acpi/arm64/gtdt.c +++ b/drivers/acpi/arm64/gtdt.c @@ -147,45 +147,30 @@ bool __init acpi_gtdt_c3stop(int type) * @table: The pointer to GTDT table. * @platform_timer_count: It points to a integer variable which is used * for storing the number of platform timers. - * This pointer could be NULL, if the caller - * doesn't need this info. - * - * Return: 0 if success, -EINVAL if error. */ -int __init acpi_gtdt_init(struct acpi_table_header *table, +void __init acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count) { - void *platform_timer; struct acpi_table_gtdt *gtdt; gtdt = container_of(table, struct acpi_table_gtdt, header); acpi_gtdt_desc.gtdt = gtdt; acpi_gtdt_desc.gtdt_end = (void *)table + table->length; acpi_gtdt_desc.platform_timer = NULL; - if (platform_timer_count) - *platform_timer_count = 0; if (table->revision < 2) { pr_warn("Revision:%d doesn't support Platform Timers.\n", table->revision); - return 0; + return; } if (!gtdt->platform_timer_count) { pr_debug("No Platform Timer.\n"); - return 0; + return; } - platform_timer = (void *)gtdt + gtdt->platform_timer_offset; - if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt)) { - pr_err(FW_BUG "invalid timer data.\n"); - return -EINVAL; - } - acpi_gtdt_desc.platform_timer = platform_timer; - if (platform_timer_count) - *platform_timer_count = gtdt->platform_timer_count; - - return 0; + acpi_gtdt_desc.platform_timer = (void *)gtdt + gtdt->platform_timer_offset; + *platform_timer_count = gtdt->platform_timer_count; } static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block, @@ -377,7 +362,7 @@ static int __init gtdt_sbsa_gwdt_init(void) { void *platform_timer; struct acpi_table_header *table; - int ret, timer_count, gwdt_count = 0; + int ret, timer_count = 0, gwdt_count = 0; if (acpi_disabled) return 0; @@ -394,8 +379,8 @@ static int __init gtdt_sbsa_gwdt_init(void) * to re-initialize them with permanent mapped pointer values to let the * GTDT parsing possible. */ - ret = acpi_gtdt_init(table, &timer_count); - if (ret || !timer_count) + acpi_gtdt_init(table, &timer_count); + if (!timer_count) goto out_put_gtdt; for_each_platform_timer(platform_timer) { diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 03733101e231..4ca06aba68a4 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -1741,7 +1741,7 @@ static int __init arch_timer_mem_acpi_init(int platform_timer_count) /* Initialize per-processor generic timer and memory-mapped timer(if present) */ static int __init arch_timer_acpi_init(struct acpi_table_header *table) { - int ret, platform_timer_count; + int ret, platform_timer_count = 0; if (arch_timers_present & ARCH_TIMER_TYPE_CP15) { pr_warn("already initialized, skipping\n"); @@ -1750,9 +1750,7 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table) arch_timers_present |= ARCH_TIMER_TYPE_CP15; - ret = acpi_gtdt_init(table, &platform_timer_count); - if (ret) - return ret; + acpi_gtdt_init(table, &platform_timer_count); arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] = acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 3a21f1cf126f..7ebc031ff8c0 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -750,7 +750,7 @@ int acpi_reconfig_notifier_register(struct notifier_block *nb); int acpi_reconfig_notifier_unregister(struct notifier_block *nb); #ifdef CONFIG_ACPI_GTDT -int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count); +void __init acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count); int acpi_gtdt_map_ppi(int type); bool acpi_gtdt_c3stop(int type); int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);