From nobody Sun Feb 8 14:22:20 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 137EB1F30C3 for ; Fri, 14 Nov 2025 02:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763088586; cv=none; b=SfLfYUsb1yXPn+2vc4Dyr88a1x1WwoKYWtwxkFoKyuTuS3H7WE57mn1BNB7Gx70yC4LMHtRs84+b6TC/qNbROoYD998p3bw7VWnNis7q0rYPG0f4kVo8jZd4vsPsd8TucxYHc2dUVlJU6Qb/5vRt/kG+uqJF492R0/HcSJojIyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763088586; c=relaxed/simple; bh=/AVZvCwm0rNZ3V55ilxDg8NmKdfKzE7OO/2VsOP9cdk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Caef4YgUiyGRv6ZnXuDr9VbseCt9lU2sYPs39QxJOXHg9e+0ut247436/PS3CxOjMs16IIlvdFsqIntpt/HUdD5eBpv7Dt4h3J1OjoTUqcjTXf54YwqMa/ikRoMRwl4cM9puiQzgVM4NERWS0lwMiQSKwtAbgLAYm7YMm9XgPbk= 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=WfhLTRsf; arc=none smtp.client-ip=209.85.216.48 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="WfhLTRsf" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-340a5c58bf1so1089429a91.2 for ; Thu, 13 Nov 2025 18:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763088584; x=1763693384; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5D9Z7Z5u/cgpb/w/GR7Wd+ItF+Fj8eOwQSf05yxiiOA=; b=WfhLTRsfdZ1kkUunPup1lOUj4l01K+GAjZ52B381klRFwP99wTgNfFww/sT+8dR7OT fHJJDF/ZghejWcKKHlsOE5twLL0GDpSFg7IhhyxbtaW8lR6BCPy2x5PoGG+L95zmniH1 pDcznYQnnXxUdxKxNdJN6+CzG4+vc9uSAVfYUKmhB9Q3fhed4A5jgChsBCk+Qu5oOuGR iNiZfSk21SVv5Ts5SgcMBxnH6ugqh8Vo5IWGF1bvkzjcBcKc33dJ+GtDq29s3sFZ2f7v 5CdukHnZx/Ztw7aLmL/JgG54JflPyEnS7v5kWl/9omC5U2iN7esUtCPoF3m1IyABhe5Z g9Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763088584; x=1763693384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5D9Z7Z5u/cgpb/w/GR7Wd+ItF+Fj8eOwQSf05yxiiOA=; b=DNIdyAtCLKikKYDAoid4w+RdSrgCNEWB1VHMVFHsdbbO5jRzFHYlK4QobTj5EYvdch FWtuYzaBDElYRzJj4luq+Vv5WeAlEcMrlH8Vtv/4uAXv6eCnl3Ef0b1bGdDuKNHJEqUJ +WZB+dIVkZYFqgUhccpfabIm2cwr8I93NNZU7redh513d1jutvdxdW5hDpCzMqnpscua PrH3rMwVSti6J0dygiN+RENRNWnvdVGNyoCLKyEIM2g0LoFYUjmI0G0c2wrc4mY0V5DG ykwVyyGQFqYZlDGQLH2eBbSJPMnqqDPz9GFW9W55VwAWsN3Ega28IJVPWNqhccpjjH7O sOeA== X-Forwarded-Encrypted: i=1; AJvYcCXi0lR8RBEzxnORHjNPxyQNB7ooYrmR9dVVL4S2wLONns9I9uafknzeGeDyjztHsd2xc/9r0nRVcw1KQ6w=@vger.kernel.org X-Gm-Message-State: AOJu0YxsQNPQXnk+Nglfx/IWIJrk/azwKo1h+TLcYNkLatFAWG3e8Ids iJrSQHyQIM7DoXBoOMqhaqHo+cOnZlhM7p+GVWwJJodxD5UEYZqxYiln X-Gm-Gg: ASbGncsvF72hQArOVaCzjQ91ommwRvBd64zKh9VD9iYJZ3h5lOOasLng+VwivDMPTo6 CvUJz6oxrKlQEAUQvlshI7U/sOb7qO4vvEizGESrQos1cP5Mrxc/LwhWYxJetxnWHqTSLHyDErG Nf4CEr5c85daTFq/sMqQmP6w4LKzH9olMdDfymrnC52gu0+TDaVahjayGO/4EaeyQbBU259HoAR dJ2ZQyfEyoGYxrDAzT72TTOyyxCSmmsIHYvdXXTA+UQpGAe5nOsf6QR1gjUhHDRsISbJSku1WE0 BdQ5/L7nV4UIMMtxWrAr787Kp8xQ/ZoHXq2t/ljuTA5CLvapbHNClvzZ/7WN+86XZyvYqmNWJdG Dm/tSE6NW4Mdk0LTE2N/+LsTN0t07b+vFadvdoIW0YagUxX8YLvKg+lEp53gWx3eClIg0dn0RQs gzxsmbTdQQ5a5jdql7yVGzMbyFks+dKEjULQ== X-Google-Smtp-Source: AGHT+IHLZ4Y11EjkEnPFEjZxGWu0dFKQkEZR5WZECy49z7o4E+nToMqB2eeJNfh0z3SWnTW5ruWgHg== X-Received: by 2002:a17:90b:17cc:b0:33b:bf8d:6172 with SMTP id 98e67ed59e1d1-343fa74be0amr1536731a91.34.1763088583893; Thu, 13 Nov 2025 18:49:43 -0800 (PST) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bc37818885fsm3306517a12.38.2025.11.13.18.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 18:49:43 -0800 (PST) Received: from hqs-appsw-a2o.mp600.macronix.com (linux-patcher [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id DD759801D4; Fri, 14 Nov 2025 10:52:26 +0800 (CST) From: Cheng Ming Lin To: richard@nod.at, chengzhihao1@huawei.com, miquel.raynal@bootlin.com, vigneshr@ti.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: alvinzhou@mxic.com.tw, leoyu@mxic.com.tw, Cheng Ming Lin Subject: [PATCH v2 1/1] mtd: ubi: skip programming unused bits in ubi headers Date: Fri, 14 Nov 2025 10:44:52 +0800 Message-Id: <20251114024452.2927429-2-linchengming884@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251114024452.2927429-1-linchengming884@gmail.com> References: <20251114024452.2927429-1-linchengming884@gmail.com> 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 Content-Type: text/plain; charset="utf-8" From: Cheng Ming Lin This patch prevents unnecessary programming of bits in ec_hdr and vid_hdr that are not used or read during normal UBI operation. These unused bits are typcially already set to 1 in erased flash and do not need to be explicitly programmed to 0 if they are not used. Programming such unused areas offers no functional benefit and may result in unnecessary flash wear, reducing the overall lifetime of the device. By skipping these writes, we preserve the flash state as much as possible and minimize wear caused by redundant operations. This change ensures that only necessary fields are written when preparing UBI headers, improving flash efficiency without affecting functionality. Additionally, the Kioxia TC58NVG1S3HTA00 datasheet (page 63) also notes that continuous program/erase cycling with a high percentage of '0' bits in the data pattern can accelerate block endurance degradation. This further supports avoiding large 0x00 patterns. Link: https://europe.kioxia.com/content/dam/kioxia/newidr/productinfo/datas= heet/201910/DST_TC58NVG1S3HTA00-TDE_EN_31442.pdf Signed-off-by: Cheng Ming Lin Reviewed-by: Miquel Raynal Reviewed-by: Zhihao Cheng --- drivers/mtd/ubi/io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index a4999bce4..dfb9c27c0 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -868,6 +868,8 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnu= m, return -EROFS; } =20 + memset((char *)ec_hdr + UBI_EC_HDR_SIZE, 0xFF, ubi->ec_hdr_alsize - UBI_E= C_HDR_SIZE); + err =3D ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); return err; } @@ -1150,6 +1152,14 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int= pnum, return -EROFS; } =20 + if (ubi->vid_hdr_shift) { + memset((char *)p, 0xFF, ubi->vid_hdr_shift); + memset((char *)p + ubi->vid_hdr_shift + UBI_VID_HDR_SIZE, 0xFF, + ubi->vid_hdr_alsize - (ubi->vid_hdr_shift + UBI_VID_HDR_SIZE)); + } else { + memset((char *)p + UBI_VID_HDR_SIZE, 0xFF, ubi->vid_hdr_alsize - UBI_VID= _HDR_SIZE); + } + err =3D ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, ubi->vid_hdr_alsize); return err; --=20 2.25.1