From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 621DB34C815 for ; Thu, 9 Apr 2026 07:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775719577; cv=none; b=WFIVrGvRdFdT8sJ+NNpIqC7oQPrl+CQyJKxlH9vMn6xo03sBp9zxicsVMUGVvsruOr7dpr8Z5WjXm0xL74Gxhw7D9J1qTI5vKjXsrSVI44/1jptbLdANx2mPY+K1bLlRytmSo5VQ4+1Al4LzKORTJF0uEggV3x1z5qk/iU33lTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775719577; c=relaxed/simple; bh=N3tFTXIe0UcbhnAY9UjKvbBC+dKHzqXmBymHbfPfASs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tD5lLy5H9R2EvT6iBV10mTN0nRfBKpjVVAqeEIvJK5g41vb3acvnTNlKVeoqHZVLhHttprmWDb9wkVwVoBiUWYLaxxguwYw3bAnQp0/AC/pn3YEeBtyYEQnNMFBhn2ZXll7nH9D8bCZmDcZ+C1iaxABnjerwdFbazU6voNT4y6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OFCdjgFm; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OFCdjgFm" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-488a88aeec9so6479685e9.2 for ; Thu, 09 Apr 2026 00:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775719574; x=1776324374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=lx+GdFng53t/7o6Wd37aZBbOEPPHmmkYglUTJhwvwJs=; b=OFCdjgFmY5T3qonrbiqw9qH43bu+d1LboYLKZhUxUh5WQbUNnRsENN0XYOsS4pxxTi NdiiEzpR7BGwjGxBTbvNLWzsCUgdHZEMdAEK9nbFF8RB1Rfzbd+60Pb0RtnZOKx7n+VR v5k5WnGryhzFGRJs5+6PF72KhmfZ/3dSmDVkvkupnKIpx5/oMdBqr5ysDeUU1J9NMW/X z3Kfx/zQr/GQvPMCjwlpXWopX/LUa8RqO35+dlbhVu3AbO4Gx49XAbE7b6qKomlS+Bu6 guJU0ob8iyM/TOEvwJZ+SGmdu8KkhtQdaZhqvhqH0FiQOmxqXBaOCrFvZxmfbkvgrIRh XHVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775719574; x=1776324374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lx+GdFng53t/7o6Wd37aZBbOEPPHmmkYglUTJhwvwJs=; b=B/qPTW0UqMGOFjbhtIT2kLosdsqj9aRfLd/CLuY+tF/+hqk89D0Sno/5y4tTRH1OwU MXlHt0y8IqRDtryt9DAeXjQ4wcHxXFprImZNvt3TVb3H/aWAr2N0geMCLknyJu92MI8g rI9KY4ExgSjANxw7aEdM2YEGSxXuM8icZrcfrzek1BiVfDQ3ptEAzVMtUb4tFauxjRyb vWlclc8sGrC/+uRMGu8lD3ZvMU1NPPN3g06Z5zJvCkqRIj2ZWfUql38ZAEhLnvclRtIw rYH4jMc2W5X+Fq5j9eJxEpLsy05QKgXoOfMWPnuHICLqSjHxCHYTOiIUjhCncBJA4JFg Vvig== X-Forwarded-Encrypted: i=1; AJvYcCVuxKuaMuq3jcvSrskTLgpmpPO+ZIvkyim2hFLHN5GtMv3AHbbYOk2oAdPKWg7nKsUQx7hD+A2BibbI/7o=@vger.kernel.org X-Gm-Message-State: AOJu0YwF9MZZQMJqdJQJtrABI5WTfC2MUjULNcNk6o9vi0Jj2mmzv7uf mguM9XFJoogR5AWHHnR5TkqGoD2aY/dRSo5FTKHQ10fSguLaXw9Opaoz X-Gm-Gg: AeBDieuAcDewknwg3qGGzizFX9w31w8W1BJ+ZMkeelbKqlqb592rj6WAhFYawUrPiDd 58A4PepLKhiKeiahhm4gS0dkv1ZAYa1NyevNxt/Hm3aM5b/Jv7X1rQCeXPXTQvys/Tk56/GFkn0 i70IJApG7QboshJxJfTgGsaLP1S7c9l4SKMqdhin5x55O+Soq2aftv6M+ahahz8//TdMYqiA6vy LvmMwT4yTinPVzjJAJcbojyWEZG917V2bbc9zxwMnTEYybkyDHUljINUeAMXi7uWeVJkBZzdPB0 F5y+SWdm3QoXJQmwAnx7Mt6lfKHmyFGR19w+frYUVdW0+0RAkwsFtuT+VX5h9TMAac3QNr4Z1XF pyfIpy6hr+ENj77xTD7/qavXdAzW/bWKB/J7VRkM1aQpvX8hopa/dFrJXtCghIl5gMU4+6YiFig YBkk1jJgek4J3UczTIxwy75e/Ryz6sAWoYaiMUr1UYeBVfKXkyabnzqZKyhb17FIbQ X-Received: by 2002:a05:600c:3b87:b0:486:fe23:1707 with SMTP id 5b1f17b1804b1-488997ac1bdmr347254275e9.20.1775719573502; Thu, 09 Apr 2026 00:26:13 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488cf9e8ab4sm36505175e9.4.2026.04.09.00.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2026 00:26:13 -0700 (PDT) Date: Thu, 9 Apr 2026 08:26:11 +0100 From: David Laight To: Andy Shevchenko Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Lukas Wunner , Andrew Morton Subject: Re: [PATCH v3 1/1] mtd: cfi_cmdset_0001: Factor out do_write_buffer_locked() to reduce stack frame Message-ID: <20260409082611.73fac9ab@pumpkin> In-Reply-To: <20260408211407.2295175-1-andriy.shevchenko@linux.intel.com> References: <20260408211407.2295175-1-andriy.shevchenko@linux.intel.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 8 Apr 2026 23:11:48 +0200 Andy Shevchenko wrote: > Compiler is not happy about used stack frame: >=20 > drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer': > drivers/mtd/chips/cfi_cmdset_0001.c:1887:1: error: the frame size of 1296= bytes is larger than 1280 bytes [-Werror=3Dframe-larger-than=3D] >=20 > Fix this by factoring out do_write_buffer_locked(). Does this just split the large stack frame between two nested functions? I'd also expect the compiler to inline do_write_buffer_locked() so it makes little difference. OTOH I can't immediately see where the large stack frame comes from. David >=20 > Signed-off-by: Andy Shevchenko > --- > v3: addressed set but unused variables when MTD_XIP=3Dy (LKP) > v2: kept DIS/ENABLE_VPP paired >=20 > drivers/mtd/chips/cfi_cmdset_0001.c | 88 +++++++++++++++++------------ > 1 file changed, 51 insertions(+), 37 deletions(-) >=20 > diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_= cmdset_0001.c > index 5a4d2e16a9d1..7733e076ad40 100644 > --- a/drivers/mtd/chips/cfi_cmdset_0001.c > +++ b/drivers/mtd/chips/cfi_cmdset_0001.c > @@ -1154,7 +1154,8 @@ static void __xipram xip_enable(struct map_info *ma= p, struct flchip *chip, > =20 > static int __xipram xip_wait_for_operation( > struct map_info *map, struct flchip *chip, > - unsigned long adr, unsigned int chip_op_time_max) > + unsigned long adr, unsigned long inval_adr, int inval_len, > + unsigned int chip_op_time, unsigned int chip_op_time_max) > { > struct cfi_private *cfi =3D map->fldrv_priv; > struct cfi_pri_intelext *cfip =3D cfi->cmdset_priv; > @@ -1276,8 +1277,7 @@ static int __xipram xip_wait_for_operation( > #define XIP_INVAL_CACHED_RANGE(map, from, size) \ > INVALIDATE_CACHED_RANGE(map, from, size) > =20 > -#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, u= sec, usec_max) \ > - xip_wait_for_operation(map, chip, cmd_adr, usec_max) > +#define INVAL_CACHE_AND_WAIT xip_wait_for_operation Isn't that separate and unrelated? The compiler might optimise away the parameters you are adding back. David > =20 > #else > =20 > @@ -1720,42 +1720,24 @@ static int cfi_intelext_write_words (struct mtd_i= nfo *mtd, loff_t to , size_t le > } > =20 > =20 > -static int __xipram do_write_buffer(struct map_info *map, struct flchip = *chip, > - unsigned long adr, const struct kvec **pvec, > - unsigned long *pvec_seek, int len) > +static int __xipram do_write_buffer_locked(struct map_info *map, struct = flchip *chip, > + unsigned long cmd_adr, unsigned long adr, > + const struct kvec **pvec, > + unsigned long *pvec_seek, int len) > { > struct cfi_private *cfi =3D map->fldrv_priv; > map_word status, write_cmd, datum; > - unsigned long cmd_adr; > - int ret, wbufsize, word_gap, words; > + int ret, word_gap, words; > const struct kvec *vec; > unsigned long vec_seek; > unsigned long initial_adr; > int initial_len =3D len; > =20 > - wbufsize =3D cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; > - adr +=3D chip->start; > initial_adr =3D adr; > - cmd_adr =3D adr & ~(wbufsize-1); > - > - /* Sharp LH28F640BF chips need the first address for the > - * Page Buffer Program command. See Table 5 of > - * LH28F320BF, LH28F640BF, LH28F128BF Series (Appendix FUM00701) */ > - if (is_LH28F640BF(cfi)) > - cmd_adr =3D adr; > =20 > /* Let's determine this according to the interleave only once */ > write_cmd =3D (cfi->cfiq->P_ID !=3D P_ID_INTEL_PERFORMANCE) ? CMD(0xe8)= : CMD(0xe9); > =20 > - mutex_lock(&chip->mutex); > - ret =3D get_chip(map, chip, cmd_adr, FL_WRITING); > - if (ret) { > - mutex_unlock(&chip->mutex); > - return ret; > - } > - > - XIP_INVAL_CACHED_RANGE(map, initial_adr, initial_len); > - ENABLE_VPP(map); > xip_disable(map, chip, cmd_adr); > =20 > /* =C2=A74.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5= is set > @@ -1789,7 +1771,7 @@ static int __xipram do_write_buffer(struct map_info= *map, struct flchip *chip, > xip_enable(map, chip, cmd_adr); > printk(KERN_ERR "%s: Chip not ready for buffer write. Xstatus =3D %lx,= status =3D %lx\n", > map->name, Xstatus.x[0], status.x[0]); > - goto out; > + return ret; > } > =20 > /* Figure out the number of words to write */ > @@ -1853,7 +1835,7 @@ static int __xipram do_write_buffer(struct map_info= *map, struct flchip *chip, > chip->state =3D FL_STATUS; > xip_enable(map, chip, cmd_adr); > printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name= ); > - goto out; > + return ret; > } > =20 > /* check for errors */ > @@ -1866,21 +1848,53 @@ static int __xipram do_write_buffer(struct map_in= fo *map, struct flchip *chip, > map_write(map, CMD(0x70), cmd_adr); > xip_enable(map, chip, cmd_adr); > =20 > - if (chipstatus & 0x02) { > - ret =3D -EROFS; > - } else if (chipstatus & 0x08) { > + if (chipstatus & 0x02) > + return -EROFS; > + > + if (chipstatus & 0x08) { > printk(KERN_ERR "%s: buffer write error (bad VPP)\n", map->name); > - ret =3D -EIO; > - } else { > - printk(KERN_ERR "%s: buffer write error (status 0x%lx)\n", map->name,= chipstatus); > - ret =3D -EINVAL; > + return -EIO; > } > =20 > - goto out; > + printk(KERN_ERR "%s: buffer write error (status 0x%lx)\n", map->name, = chipstatus); > + return -EINVAL; > } > =20 > xip_enable(map, chip, cmd_adr); > - out: DISABLE_VPP(map); > + return 0; > +} > + > +static int __xipram do_write_buffer(struct map_info *map, struct flchip = *chip, > + unsigned long adr, const struct kvec **pvec, > + unsigned long *pvec_seek, int len) > +{ > + struct cfi_private *cfi =3D map->fldrv_priv; > + unsigned long cmd_adr; > + int ret, wbufsize; > + > + wbufsize =3D cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; > + adr +=3D chip->start; > + cmd_adr =3D adr & ~(wbufsize - 1); > + > + /* Sharp LH28F640BF chips need the first address for the > + * Page Buffer Program command. See Table 5 of > + * LH28F320BF, LH28F640BF, LH28F128BF Series (Appendix FUM00701) */ > + if (is_LH28F640BF(cfi)) > + cmd_adr =3D adr; > + > + mutex_lock(&chip->mutex); > + ret =3D get_chip(map, chip, cmd_adr, FL_WRITING); > + if (ret) { > + mutex_unlock(&chip->mutex); > + return ret; > + } > + > + XIP_INVAL_CACHED_RANGE(map, adr, len); > + ENABLE_VPP(map); > + > + ret =3D do_write_buffer_locked(map, chip, cmd_adr, adr, pvec, pvec_seek= , len); > + > + DISABLE_VPP(map); > put_chip(map, chip, cmd_adr); > mutex_unlock(&chip->mutex); > return ret;