From patchwork Mon Jan 31 02:52:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 538474 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1405666imr; Sun, 30 Jan 2022 18:52:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxv/2aP6rROUWOY9kIUyOHH2l/TB95TzW+BvgTRDWiEV55V8r9qbPo5sHdo0N1XFaZfJopK X-Received: by 2002:a17:907:6e09:: with SMTP id sd9mr11891683ejc.259.1643597563999; Sun, 30 Jan 2022 18:52:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643597563; cv=none; d=google.com; s=arc-20160816; b=R3IZLWHcb4tdVXpt5/flgPIp6ovUYQQgnkY+NrEJUS3yI5H1tAwl+rMeEuSM+G52ms 5SPO5Tjp6vkbcpLv3kmct0yfv/urcGotR3EgJvAkbry3SXnZeC6T7T/3BtqDo2mCvwFs JtXENeQk6e7+sRT67Y0qnklkBi1m+LbIaMuAIgsrWSF9DC9a0rCDkP+sby5I3tab4T+T /quWPwTcrKXCC6I7iT0oxnzuaAI+6MA1gJ+zCsYbVk3P1V2kH2lQfuHRAPGgj4vss8rV ukewHuAUrxfkH06n8ucQU+KSMKef3n6fhFBUSMPxFWHKsCBne1Nz64ea1/I45k/A8EXZ HOTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=vpQWFMVMzShvFAH5PwEDHsRmeXWZEEJwbCUaZZsG4GGTg1CU0/UPxGDhzguQVILQWE AKZ4ynL09naNUnUL94IdKX5nVm6QBnaTn5WiD5hPb1aHUhubUC2WIq3heaLWHoua8CW7 rWq11+rj9vNkuIHJWMmnXHziw0k4Vn1apqM0zdZVb5i2jqyWFlKkhLAEurmPP91RwksN Najibxe4KjkvvclOc61d1hDFRGA2b4o3rSaKzKnoYqWCFNeuVvtj7eS+J6yPzQcvoDhX eiiJyiQa4aWVlcJdImJXguxYCI6KLA+0saxOSgmMipv/CAvJwmpzEOcDPGDaAjJna5sz wLzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mz20xJUR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id b8si6340230ejl.928.2022.01.30.18.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mz20xJUR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 874788366A; Mon, 31 Jan 2022 03:52:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Mz20xJUR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F095833A2; Mon, 31 Jan 2022 03:52:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 095FB833BE for ; Mon, 31 Jan 2022 03:52:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pj1-x102d.google.com with SMTP id h12so12551394pjq.3 for ; Sun, 30 Jan 2022 18:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=Mz20xJURs4LSfeWwWrNQtuvCq5YgUUjtGscQXiNK7XCElFVFhLXe7QKtkhxw/EXzWs ypqUNWx4/DKaVsEqpIBb4AjMOp1wA60IRCyr1hbu+B7kVAPktJ5IFPIY20umeUT5Stp9 zPw68EHL+tduu5tsqviFMTxzDK9ywZZDcuTgvmYCRu0cEGzBzhWzvA7hPs8+2d+BcvSr kCom++nex1f5HZyqLx+dvhNFVBjUBKZt5f7KlmN3B20btKStyRuXdkp7spPNkJte5/OG K8MWPbp2K+z+XhSU8fowdgDFaYF2PKT2zMo0tvXcDbBJGsGOiftIhO/BvcBdkBVedWj2 gJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=5ZnnKK4lyRFbdYdMV44O8d6xk7WoVOi45h9RZoqvpzs=; b=GyxJUb+6q1duMegxQTVzbIXQie2MpOwo/G7WB8FCd+MSZLPExjCp5BmGH3PNxIhkB7 mxHYmFqoj9qjbIofwhzj/FRXsQAiMSgKydN1to4g/hdAOwZXV13XKWWojl7VKjltyF48 dyXVZbP3eYgKEfgfcEKO0NQ2xq1M1zQcvFlT7EbrtfK/6k2Heeb6su/AYDFZtXpcedJw DGuoqvnfy7/s9YgyIEzlAgbhR3306jFjTvPwLKJ/rla8jpedWnzITFLX3oJTtyGzedle 9IJ54Usd5VkTEbvajOdfYfPZlWbRUrcNXGOXWdsCBDga0iUN6fqWqdqQPFLqf87qXWso x/ug== X-Gm-Message-State: AOAM531fGygY3PUnOn2RzICjOqsActelXqT+2YZP3NfU58MBHx+21g+x 244BtfwLaP+unBEF01RG5yPMEA== X-Received: by 2002:a17:902:6948:: with SMTP id k8mr19237554plt.136.1643597552207; Sun, 30 Jan 2022 18:52:32 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id h19sm8739874pjv.38.2022.01.30.18.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 18:52:31 -0800 (PST) From: Masami Hiramatsu To: Tom Rini , Lukasz Majewski Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sughosh.ganu@linaro.org, jaswinder.singh@linaro.org Subject: [PATCH v2 2/5] DFU: Accept redundant spaces and tabs in dfu_alt_info Date: Mon, 31 Jan 2022 11:52:29 +0900 Message-Id: <164359754906.280839.1412862787511934825.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164359753172.280839.8310577813724924540.stgit@localhost> References: <164359753172.280839.8310577813724924540.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean If dfu_alt_info has repeated spaces or tab (for indentation or readability), the dfu fails to parse it. For example, if dfu_alt_info="mtd nor1=image raw 100000 200000" (double spaces after "raw"), the image entity start address is '0' and the size '0x100000'. This is because the repeated space is not skipped. Use space and tab as a separater and apply skip_spaces() to skip redundant spaces and tabs. Signed-off-by: Masami Hiramatsu --- drivers/dfu/dfu.c | 6 ++++-- drivers/dfu/dfu_mmc.c | 11 ++++++++--- drivers/dfu/dfu_mtd.c | 8 ++++++-- drivers/dfu/dfu_nand.c | 11 ++++++++--- drivers/dfu/dfu_ram.c | 3 ++- drivers/dfu/dfu_sf.c | 12 +++++++++--- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 66c41b5e76..18154774f9 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -123,9 +123,10 @@ int dfu_config_interfaces(char *env) s = env; while (s) { ret = -EINVAL; - i = strsep(&s, " "); + i = strsep(&s, " \t"); if (!i) break; + s = skip_spaces(s); d = strsep(&s, "="); if (!d) break; @@ -502,8 +503,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, char *st; debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr); - st = strsep(&s, " "); + st = strsep(&s, " \t"); strlcpy(dfu->name, st, DFU_NAME_SIZE); + s = skip_spaces(s); dfu->alt = alt; dfu->max_buf_size = 0; diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 3dab5a5f63..d747ede66c 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -351,11 +351,12 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mmc.dev_num = dectoul(devstr, NULL); for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " "); + *parg = strsep(&s, " \t"); if (*parg == NULL) { pr_err("Invalid number of arguments.\n"); return -ENODEV; } + s = skip_spaces(s); } entity_type = argv[0]; @@ -390,9 +391,11 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * specifying the mmc HW defined partition number */ if (s) - if (!strcmp(strsep(&s, " "), "mmcpart")) + if (!strcmp(strsep(&s, " \t"), "mmcpart")) { + s = skip_spaces(s); dfu->data.mmc.hw_partition = simple_strtoul(s, NULL, 0); + } } else if (!strcmp(entity_type, "part")) { struct disk_partition partinfo; @@ -412,8 +415,10 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * specifying the mmc HW defined partition number */ if (s) - if (!strcmp(strsep(&s, " "), "offset")) + if (!strcmp(strsep(&s, " \t"), "offset")) { + s = skip_spaces(s); offset = simple_strtoul(s, NULL, 0); + } dfu->layout = DFU_RAW_ADDR; dfu->data.mmc.lba_start = partinfo.start + offset; diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c index cce9ce0845..27c011f537 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -12,6 +12,7 @@ #include #include #include +#include static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) { @@ -285,11 +286,14 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.mtd.info = mtd; dfu->max_buf_size = mtd->erasesize; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.mtd.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.mtd.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index e53b35e42b..76761939ab 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -201,11 +201,14 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->data.nand.ubi = 0; dfu->dev_type = DFU_DEV_NAND; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.nand.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.nand.size = hextoul(s, &s); } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) { char mtd_id[32]; @@ -216,7 +219,9 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; dev = dectoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nand", dev, part - 1); diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index cc7e45ba33..361a3ff8af 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -60,11 +60,12 @@ int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) const char **parg = argv; for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " "); + *parg = strsep(&s, " \t"); if (*parg == NULL) { pr_err("Invalid number of arguments.\n"); return -ENODEV; } + s = skip_spaces(s); } dfu->dev_type = DFU_DEV_RAM; diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index b72493ced8..993e951bc3 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -13,6 +13,7 @@ #include #include #include +#include static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size) { @@ -178,11 +179,14 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->dev_type = DFU_DEV_SF; dfu->max_buf_size = dfu->data.sf.dev->sector_size; - st = strsep(&s, " "); + st = strsep(&s, " \t"); + s = skip_spaces(s); if (!strcmp(st, "raw")) { dfu->layout = DFU_RAW_ADDR; dfu->data.sf.start = hextoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); dfu->data.sf.size = hextoul(s, &s); } else if (CONFIG_IS_ENABLED(DFU_SF_PART) && (!strcmp(st, "part") || !strcmp(st, "partubi"))) { @@ -195,7 +199,9 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_RAW_ADDR; dev = dectoul(s, &s); - s++; + if (!isspace(*s)) + return -1; + s = skip_spaces(s); part = dectoul(s, &s); sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1);