From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E753E18785C; Wed, 9 Oct 2024 11:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728473619; cv=none; b=IBhjjh/vgn3sq3KyytmQNwvZwbh+C9rfwAgBYaUwCmaKg8xinJOYNjLhwO4ESXxJ9RA0yVyoRhGo/rVIVwRiI4FAvSLgAzGmjvjaKJbBAUGdTy/l6+0E7WIl3ca0zsGouAWaktUlh3ZtsMs++oBc10zFan0jDlQjifrlzGLH20A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728473619; c=relaxed/simple; bh=AqkNfnjES4sBMH18sozhyHW+UH06mk5jmH+B+yAPjRE=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=Cfea25f80qpvgE9g89tJMFxN0ybmevT7wZX0TjcrAVUlfIiePnc+q+ehMWz8G9oATXuDNHGajGVJ6kmz5lZ4BTxP34+nxwDsjwQFt9i3/Hu4ya2SHjfdozivbj9YNcQ9bX05j31VeuY8Vt8pjmL+0KVxG7bzhm1OoHqg6WYpXaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A/FVdKRW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A/FVdKRW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73519C4CEC5; Wed, 9 Oct 2024 11:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728473618; bh=AqkNfnjES4sBMH18sozhyHW+UH06mk5jmH+B+yAPjRE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=A/FVdKRW7XzbbrBmykQFxvHou/ZDX692uNCf5joHAuskJrBzIio6c7z/WFxrZmyVu XDY87VW91u9ROo6cj93jDyUCezKX6ZRBBpI9Lv+oYVykyycUWIUS0tmBGiJykzUBQh ELs//Ryzxc1KJPfTkqfu+hWio5N4uC4s2oo/f7oiTHcIwyXI6nOqBiKRebCibPMahT Qqce7VSLvpVfBnrrDaS8lKGcjHaPu2Jtfwpu4/zgw4WwKGahkks8ViIj5X3faZsftZ 1wTebe8LsSvp+iHdZDByEjJ1reQhOG9Ga2qzcrqbkcnqruiZVmfUAmK5bIGRoJSpd3 hAFLpEUEU4Fzw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1syUwh-001oIk-WA; Wed, 09 Oct 2024 12:33:36 +0100 Date: Wed, 09 Oct 2024 12:33:35 +0100 Message-ID: <86r08p5x4g.wl-maz@kernel.org> From: Marc Zyngier To: Zheng Zengkai Cc: , , , , , , , , , , Subject: Re: [PATCH v2] ACPI: GTDT: simplify acpi_gtdt_init() implementation In-Reply-To: <57e9adb8-a34a-6d63-24b8-4ad0abb74bf9@huawei.com> References: <20241008082429.33646-1-zhengzengkai@huawei.com> <86v7y355zr.wl-maz@kernel.org> <57e9adb8-a34a-6d63-24b8-4ad0abb74bf9@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: zhengzengkai@huawei.com, lpieralisi@kernel.org, guohanjun@huawei.com, sudeep.holla@arm.com, mark.rutland@arm.com, rafael@kernel.org, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 08 Oct 2024 15:04:52 +0100, Zheng Zengkai wrote: >=20 >=20 > =E5=9C=A8 2024/10/8 16:55, Marc Zyngier =E5=86=99=E9=81=93: > > On Tue, 08 Oct 2024 09:24:29 +0100, > > Zheng Zengkai wrote: > >> 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)' > > There is no such language in the spec. It simply says "Offset to the > > Platform Timer Structure[] array from the start of this table". > OK, I mean that in current code, the condition of this check is redundant. That's not my reading if it. Where do you see another validity check that makes this one superfluous? > >> 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. > > And ACPI tables are well known to be always correct, right? > Not always, check is needed, but should be changed. You are not changing it, you are getting rid of it, and I don't see you replacing it with anything else. > >> 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 stori= ng > >> 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. > >>=20 > >> Signed-off-by: Zheng Zengkai > >> --- > >> Changes in v2: > >> - initialize 'ret' in gtdt_sbsa_gwdt_init() to silence build warning > >>=20 > >> v1: https://lore.kernel.org/all/20240930030716.179992-1-zhengzengkai@h= uawei.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(-) > >>=20 > >> 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 u= sed > >> * 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 =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; > >> 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 =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_time= r_offset; > > And now you are trusting something that potentially points to some > > unexpected location, blindly using it. It is bad enough that the > > current checks are pretty poor (no check against the end of the > > table for the first timer entry), but you are making it worse. > >=20 > > M. >=20 > Can I use the second and third bytes (the length) of platform timer > structure to check against the end of the table ? That's how it is supposed to be done indeed. M. --=20 Without deviation from the norm, progress is not possible.