From nobody Wed Nov 27 18:54:36 2024 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14A3F1E04AE; Tue, 8 Oct 2024 07:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728373839; cv=none; b=MeFBPMarrm402iWWrxg5wNgQYw3bmTuCjmZMN0/6jJe2cAnIRVBrABbXP5APgkFDi9ZsB1D+exkKnMNQ9GGgof5wt/Io0QdB0siqRVCDwVBJ34qe9CbCefU35kTGyDUJGH39YxPW1DGVi1Y+/ts5gPCxfnpl0M6udjFkT9NPo0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728373839; c=relaxed/simple; bh=2YVKqK8qdPwBNwhXjtlQ2NETdbx0YBzrRgxdzyXwlfw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZilSRKuVjziRRt6ICzQGoBn+rPoZdKLrdVRRKdQtNzQYYRkNvm82UYAuofpOQwPRHO1HFeENGn7+Fre86yKAS1rZvyttfTDRyauwTq77uBo/YuqzO1o2AZovlGbUtHxvCjrgU0ZAV8HGtWieJPrpjX0r/x8Q4GXoxvHfsjR+0L0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4XN7Tf5BVbzCt48; Tue, 8 Oct 2024 15:49:58 +0800 (CST) Received: from kwepemd200010.china.huawei.com (unknown [7.221.188.124]) by mail.maildlp.com (Postfix) with ESMTPS id 418BB14035E; Tue, 8 Oct 2024 15:50:34 +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; Tue, 8 Oct 2024 15:50:33 +0800 From: Zheng Zengkai To: , , , , , , CC: , , , , , Subject: [PATCH v2] ACPI: GTDT: simplify acpi_gtdt_init() implementation Date: Tue, 8 Oct 2024 16:24:29 +0800 Message-ID: <20241008082429.33646-1-zhengzengkai@huawei.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200010.china.huawei.com (7.221.188.124) Content-Type: text/plain; charset="utf-8" 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 --- Changes in v2: - initialize 'ret' in gtdt_sbsa_gwdt_init() to silence build warning v1: https://lore.kernel.org/all/20240930030716.179992-1-zhengzengkai@huawei= .com/ --- 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..7fe27c0edde7 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; =20 gtdt =3D container_of(table, struct acpi_table_gtdt, header); acpi_gtdt_desc.gtdt =3D gtdt; acpi_gtdt_desc.gtdt_end =3D (void *)table + table->length; acpi_gtdt_desc.platform_timer =3D NULL; - if (platform_timer_count) - *platform_timer_count =3D 0; =20 if (table->revision < 2) { pr_warn("Revision:%d doesn't support Platform Timers.\n", table->revision); - return 0; + return; } =20 if (!gtdt->platform_timer_count) { pr_debug("No Platform Timer.\n"); - return 0; + return; } =20 - platform_timer =3D (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 =3D platform_timer; - if (platform_timer_count) - *platform_timer_count =3D gtdt->platform_timer_count; - - return 0; + acpi_gtdt_desc.platform_timer =3D (void *)gtdt + gtdt->platform_timer_off= set; + *platform_timer_count =3D gtdt->platform_timer_count; } =20 static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *blo= ck, @@ -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 =3D 0; + int ret =3D 0, timer_count =3D 0, gwdt_count =3D 0; =20 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 =3D acpi_gtdt_init(table, &timer_count); - if (ret || !timer_count) + acpi_gtdt_init(table, &timer_count); + if (!timer_count) goto out_put_gtdt; =20 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 platfo= rm_timer_count) /* Initialize per-processor generic timer and memory-mapped timer(if prese= nt) */ static int __init arch_timer_acpi_init(struct acpi_table_header *table) { - int ret, platform_timer_count; + int ret, platform_timer_count =3D 0; =20 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_ta= ble_header *table) =20 arch_timers_present |=3D ARCH_TIMER_TYPE_CP15; =20 - ret =3D acpi_gtdt_init(table, &platform_timer_count); - if (ret) - return ret; + acpi_gtdt_init(table, &platform_timer_count); =20 arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] =3D acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4d5ee84c468b..2e2b168f3790 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -750,7 +750,7 @@ int acpi_reconfig_notifier_register(struct notifier_blo= ck *nb); int acpi_reconfig_notifier_unregister(struct notifier_block *nb); =20 #ifdef CONFIG_ACPI_GTDT -int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_co= unt); +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); --=20 2.20.1