From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (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 EF1201CD1E4 for ; Mon, 17 Nov 2025 13:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386393; cv=none; b=Ao1H82lfL13dLcGwmRpQLqCFszlLRev4yE+v96fCg8mUSwHSHLSklDVSxWIYxM63hqgRvvONCxjWnoot2A0JHvTWlY2cUFERS3cF9YTMD1cxcCb5R1YqpMoqdIyJQIobcylTIJq+06PnKe7D6nV4z2M/Ep1EtRfUgbrpbxDcLZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386393; c=relaxed/simple; bh=xgoTkrTawMdZiBNj93ONXASSr1HRmbaFf3O6eYogPYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JYsr1gDNyJjKEYWE7VUpl3jv/9zX+L1szmXDKfG0ebWiniAisuNp9mhW5iV61U8j1NDANWYSM/awvkRzuLuneb2Z4LCowr3dP1ddT3UahtdTBRe7ZsRjnllYAsabLzm0w5QDY/owWjmVSR0Tg1DggbmPCAgIEnkD78TTQHwfJQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hQ+k7ydX; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hQ+k7ydX" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763386377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E+me5MslrLbMsHSghG+RNKc4dr72G/B4Qkp1cVUaJyc=; b=hQ+k7ydXiMdnA1HPYzNDhs59ZKf/whLzjYCDMwu/UIcdKJjQQ+xzMnx8b4lO2uF/R/fDFs mXtqXSOXNAFYItpyv+NB1JTxyC4BZ/4Vorjc9bcaEW1927NAV8W9lJnYlozA/WJ0LvgFpL vzT/DbDkbQio4OZur5YH412LNbB3fMY= From: Yuntao Wang To: geert@linux-m68k.org Cc: krzk@kernel.org, akpm@linux-foundation.org, ardb@kernel.org, bhe@redhat.com, catalin.marinas@arm.com, changyuanl@google.com, devicetree@vger.kernel.org, geert+renesas@glider.be, geoff@infradead.org, graf@amazon.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mark.rutland@arm.com, robh@kernel.org, rppt@kernel.org, saravanak@google.com, thunder.leizhen@huawei.com, yuntao.wang@linux.dev Subject: Re: [PATCH v3 1/8] of/fdt: Consolidate duplicate code into helper functions Date: Mon, 17 Nov 2025 21:32:23 +0800 Message-ID: <20251117133223.11242-1-yuntao.wang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Mon, 17 Nov 2025 13:34:20 +0100, Geert Uytterhoeven wrote: > Hi Yuntao, > > On Mon, 17 Nov 2025 at 12:57, Yuntao Wang wrote: > > On Mon, 17 Nov 2025 08:01:59 +0100, Krzysztof Kozlowski wrote: > > > On Sat, Nov 15, 2025 at 09:47:46PM +0800, Yuntao Wang wrote: > > > > Currently, there are many pieces of nearly identical code scattered across > > > > different places. Consolidate the duplicate code into helper functions to > > > > improve maintainability and reduce the likelihood of errors. > > > > > > Not much improved. Please go to previous version and read the comments. > > > > > > Best regards, > > > Krzysztof > > > > Hi Krzysztof, > > > > scripts/checkpatch.pl indeed still reports some warnings. I noticed them, > > but I intentionally didn't fix them. > > > > Below is a list of all the warnings, along with my reasons for leaving > > them unaddressed. > > > > 1. WARNING: Missing a blank line after declarations > > #60: FILE: drivers/of/fdt.c:663: > > + int entry_cells = dt_root_addr_cells + dt_root_size_cells; > > + prop += entry_cells * entry_index; > > > > The function that triggers this warning is: > > > > void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, > > u64 *addr, u64 *size) > > { > > int entry_cells = dt_root_addr_cells + dt_root_size_cells; > > prop += entry_cells * entry_index; > > > > *addr = dt_mem_next_cell(dt_root_addr_cells, &prop); > > *size = dt_mem_next_cell(dt_root_size_cells, &prop); > > } > > > > The warning suggests adding a blank line before > > > > prop += entry_cells * entry_index; > > > > I didn't add it because, logically, > > > > int entry_cells = dt_root_addr_cells + dt_root_size_cells; > > prop += entry_cells * entry_index; > > > > forms a single block, just like > > > > *addr = dt_mem_next_cell(dt_root_addr_cells, &prop); > > *size = dt_mem_next_cell(dt_root_size_cells, &prop); > > > > I think the code is more readable without the blank line. > > > > In fact, I initially combined these two lines > > > > int entry_cells = dt_root_addr_cells + dt_root_size_cells; > > prop += entry_cells * entry_index; > > > > into a single line: > > > > prop += (dt_root_addr_cells + dt_root_size_cells) * entry_index; > > > > I added the entry_cells local variable specifically to improve readability. > > What about: > > void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, > u64 *addr, u64 *size) > { > int entry_cells = dt_root_addr_cells + dt_root_size_cells; > > prop += entry_cells * entry_index; > *addr = dt_mem_next_cell(dt_root_addr_cells, &prop); > *size = dt_mem_next_cell(dt_root_size_cells, &prop); > } > > ? > > 1. entry_cells is an intermediate variable, > 2. prop is prepared just before its use. Hi Geert, Yes, if this warning really needs to be fixed, that's exactly how it should be done. Thanks, Yuntao > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds