From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 ECEF8271456 for ; Thu, 7 May 2026 03:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778124200; cv=none; b=I6mIUvACbz9wFyvcl8xWG1yqWWV2AQXbMBC0ARUDUPPTeDdnm8E7CZKpca1O0wcbQrKnpTmmNAT/02vjg/F42+dtaqguGVfy/mYIrPkHYm/g7wBEe22hI6fsWLEcU8udZ9ulWvhFfyCQFCP6wNrZqwysyIApOGuWCeuEHjHstJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778124200; c=relaxed/simple; bh=KRRGFf3gV174d7VNFReOJyLraYSM+cj0h8HfNzhLe8A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=nqUHss1BEF1Vubs7UtKQbxx7Wvjwthmw7+scRPkt4gs906x3zZKlaXYHVt3+wQLwiiiTTeWwYCPqVX4XITux5S4vhVy+kLNYY/BT+s0VaG/V84h6hLQVJH+zKyUY4GSEzLdo3GAHp/eikiPHnw12SID+T54s3c3bm2AR0kk5JII= 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=ILorGJAN; arc=none smtp.client-ip=209.85.214.179 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="ILorGJAN" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2b941cd869cso2215725ad.1 for ; Wed, 06 May 2026 20:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778124198; x=1778728998; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=75CJdedoHoohO75aM9mgs334GNhMlImFEHlEZ7W1x1o=; b=ILorGJANqaVPaZJcP/8wgxFFE1NTm4al+xkrgl9GBHAAYJHltb3uJ1dVyS30c38Ep6 Gle1hcjm9lCmg4BfIjh7cEWDdi5JfkZUq3t4Y4SCyELm643hES+m4GCVTf5avW0r0Wxk Qj7WlVtS2BSvoD+6+7neaOmr63yVvjbn5Kf2Z9g7qKRTZ26Ew1iiPWiIGXK+TjopFaPu mjIeqB1YkBcnPxbcdDZp/3W9+r+8sOYoecnm30dob1Ng3eRkKLvJxlFpZu8r2y8+5WxI xNluBxRcxe6v+gB3qAmxEY6h0njFNyakeJfy8pVyRfM2CZlbR3qlFLzX5M/OphPSrir6 c/Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778124198; x=1778728998; h=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=75CJdedoHoohO75aM9mgs334GNhMlImFEHlEZ7W1x1o=; b=hry36vzOEcM1wYccGU5+r73sJGYIvyl7FRzQTknJI8AfhrOiGCgUAmHcYvDmQhwHr6 moKxhNkQNZGzZfzgvOJELdeV9ddyq6hI16htm1tBW83zsEYgGjJQ9EF1JOz6lqIwcmDP QhlrGoYiS73Dp3RFdt3mrIbkqW1TLIGTxDEX/16nbQYJe8pAaQMDEg3e0jsS6WRD4jZq Ha+JiZbuVpGI5wHdPmmR7NacPv8b24gSAKzYJpphYO+MbOswI/EdHY+Bd87PkYrthrPC EmXsSJlhGfHrUO52bw5KNiZEBR28pOrQPOnMYq2f+i4AWVvFKiLPvn7Iufltr11GZ1+K P5Hw== X-Forwarded-Encrypted: i=1; AFNElJ8XZxoMvWbkHqmnArSDujlZdSSVKc7RzBKQ5JlrBe1QeYgkVWxlkoHprkfSpM3qv/jr/YxbcJ4Foz81E1w=@vger.kernel.org X-Gm-Message-State: AOJu0YyCU/zjY2k79fPRwZVx4gaxDkCeothPHPajoHu/zvoc6FOo77Zy ERpTFR1p6Ubsuev/WfcYIwiZ7+IECL57SX/XN30p4SIqjXLlqZBKd4Ey X-Gm-Gg: AeBDies5IpgpqJwstoc3XDuHJ1/0NVKZQysdz0kB8umFRjMRKpi4TptzYXVGjzuyu+E pKJb4TQx2sYlnc9aAcWP7bYatdmruC5ITy7TqvRfkuvXrKSE31L2XFVg/Y5P2/NaBgwVkncYMlH r3oSb2GMy43b7xAWGK5PyOgF18VV+v0oi0um7Vzl/2QqEA1g2RBCk2RGJUxdjg9JuwblUKGTYvf VfBn83v86oEpENeIdJNgF6ijeZg/2FH4Md5825X5k3I3HULVGdNN6OE0OemgzqyMfXIhhfs67Nl iUzJAmIMCEzh00WJ6Fmvt6jX78DpdNtHzWDv5UHg+Oede8OyU9ldsuG3mJHPMvX7qUMcTR4KUFv Cl+nVfReJRD9TnbkSEJYvdxGSHIGNIb/YwJ9LKR0Q+HYDRTse8yPdCU9c8vR4nz0F4QnIhVdTY/ BuXgjt7YooPKInMNLoq3fBrAPKD5UIEtXLZqG/livwPb6TOCw9BG8Ctnct6t5Zyj3yb1xrNAi8 X-Received: by 2002:a17:902:c40a:b0:2ba:13d8:d503 with SMTP id d9443c01a7336-2ba78b3fcfdmr63761215ad.8.1778124198171; Wed, 06 May 2026 20:23:18 -0700 (PDT) Received: from localhost.localdomain ([123.139.40.148]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2babadd2427sm7435005ad.38.2026.05.06.20.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 20:23:17 -0700 (PDT) From: "haoyu.lu" To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Zhihao Cheng , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Haoyu Lu Subject: [PATCH 2/2] ubi: build: replace simple_strtoul with kstrtoul in bytes_str_to_int() Date: Thu, 7 May 2026 03:23:08 +0000 Message-Id: <20260507032308.16485-2-hechushiguitu666@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260507032308.16485-1-hechushiguitu666@gmail.com> References: <20260507032308.16485-1-hechushiguitu666@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Haoyu Lu Replace the deprecated simple_strtoul() with kstrtoul() in the bytes_str_to_int() helper function. Since kstrtoul() rejects trailing non-numeric characters (such as the G/M/K suffixes), the numeric prefix is first extracted with strspn() and then parsed separately before handling the suffix. This provides proper error handling through the kstrto* family while preserving the existing suffix semantics for byte count parameters. Note: the original simple_strtoul() with base=0 accepted hexadecimal (0x prefix) and octal (0 prefix) formats, while kstrtoul() with base=10 only supports decimal. This is not a practical concern since MTD byte count parameters are always specified as decimal values in boot parameters. Signed-off-by: Haoyu Lu --- drivers/mtd/ubi/build.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 03ef195dc25c..7cb6ba4a3840 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -1426,16 +1426,27 @@ module_exit(ubi_exit); */ static int bytes_str_to_int(const char *str) { - char *endp; unsigned long result; + unsigned int num_len; + char num_buf[32]; - result = simple_strtoul(str, &endp, 0); - if (str == endp || result >= INT_MAX) { + /* Find the length of the numeric prefix */ + num_len = strspn(str, "0123456789"); + if (num_len == 0 || num_len >= sizeof(num_buf)) { pr_err("UBI error: incorrect bytes count: \"%s\"\n", str); return -EINVAL; } - switch (*endp) { + /* Parse the numeric part */ + memcpy(num_buf, str, num_len); + num_buf[num_len] = '\0'; + if (kstrtoul(num_buf, 10, &result) < 0 || result >= INT_MAX) { + pr_err("UBI error: incorrect bytes count: \"%s\"\n", str); + return -EINVAL; + } + + /* Handle suffix */ + switch (str[num_len]) { case 'G': result *= 1024; fallthrough; -- 2.17.1