From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 EC2213264E6 for ; Fri, 24 Apr 2026 17:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777050672; cv=none; b=QGYTU60afvXf2M6+Y9aYwnB0aonezoozKKvr1Vp/EzlH6JPB3kFTuy2Z31zYUlxUvEgH5Tewsz3cvFaeakjmIMzAJRPqK+a4OeJ/heM8mdgCPbPt+hBS++7f6m6McjwilPZNphxrEXgOYuSwTGS/SGluYYvElr/yEbLE1ePyHr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777050672; c=relaxed/simple; bh=PqY0DlOc5QVxOpdkHP6Ci9tpZLb7pdcsY9EgYIDAcX4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=efpB6yV1WbF3Oh1iLOLHdVjTxcAIreSwoXLimkNOS+4S0bPkatZ0Tco9RlbIvNg0hygag/03WQDrhBx5AT69juIWFP1amH30/nw0EImSIq1darFv+KwUYyZH5VFAddAdYk4wGq+H5dRdq9A1dSdrRExYYp0Ivzz3ToNSHXMGPZk= 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=j/K5AJsa; arc=none smtp.client-ip=95.215.58.176 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="j/K5AJsa" Date: Fri, 24 Apr 2026 19:10:46 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777050659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HXLgGbrRDSqViLm3/46KWass2TEKy/mGXvR1+Wp8kWc=; b=j/K5AJsa7v0oJXvIUy02/bj+vjwOEueV2gzu+u3PJAzInTCnpBj/Z6EzjwCeDgdkBPadjn Rnera4h2B4iD6AdGql7Ni3BNpaYeHmJVEZTFz7Vwxb5YbHdl5GUNJVIbcCBPP76Q9t2+Aw XzHV27gV8FGUHQQEw2rmOX8je777808= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Geert Uytterhoeven Cc: Rich Felker , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sh: use sizeof() in memchunk_cmdline_override Message-ID: References: <20260423120441.212278-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Fri, Apr 24, 2026 at 01:15:20PM +0200, Thorsten Blum wrote: > On Fri, Apr 24, 2026 at 01:05:48PM +0200, Geert Uytterhoeven wrote: > > Hi Thorsten, > > > > On Thu, 23 Apr 2026 at 14:10, Thorsten Blum wrote: > > > Replace the hard-coded string length with 'sizeof("memchunk.") - 1' and > > > remove the comment. > > > > > > Signed-off-by: Thorsten Blum > > > > Thanks for your patch! > > > > > --- a/arch/sh/mm/consistent.c > > > +++ b/arch/sh/mm/consistent.c > > > @@ -23,7 +23,7 @@ static void __init memchunk_cmdline_override(char *name, unsigned long *sizep) > > > int k = strlen(name); > > > > > > while ((p = strstr(p, "memchunk."))) { > > > - p += 9; /* strlen("memchunk.") */ > > > + p += sizeof("memchunk.") - 1; > > > > Can't you just use strlen() instead, i.e. won't the compiler optimize > > that into a constant? > > That only works if ARCH_HAS_FORTIFY_SOURCE is selected, which is not the > case for arch/sh. Otherwise I would have used strlen(). More concretely, because __HAVE_ARCH_STRLEN is set in arch/sh/include/asm/string_32.h, strlen() resolves to the arch-specific assembly implementation in arch/sh/lib/strlen.S. However, constant folding is only guaranteed when calls go through __builtin_strlen(), e.g. via the wrapper in linux/fortify-string.h, which SH does not use with dreamcast_defconfig. I also checked the disassembly, and sh4-linux-gnu-gcc (Debian 14.2.0-19) did not optimize it into a constant.