From patchwork Mon Feb 26 21:18:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 129727 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp654917lja; Mon, 26 Feb 2018 13:20:32 -0800 (PST) X-Google-Smtp-Source: AH8x226ydNDF4VM1KEsr24/d74ZmZ5XOsnuGJmX1jtOPL/fedMpAYt47b/WjlklO94eN9ub6VEjd X-Received: by 10.80.151.200 with SMTP id f8mr15866935edb.10.1519680032560; Mon, 26 Feb 2018 13:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519680032; cv=none; d=google.com; s=arc-20160816; b=BYQY+nQ2oOsPv7A4gQlXMVfI9wOYbkgmlXUPJOkSVg1sYPWtRf3BXuniCVb9wLxtMu BNoUnDTv8c3cCdRApACV2stEZfDYZOqO1tPN17yRw+aKT6nHd4V0JYB2E0Fn6gPQNjdN KG9Xwbv/F2XXOuH2fj6L7OGpk2WO0hcZ3Y+2Uh6d3xY/ymJ79V2ZRa2LVgS8vIUoX3Nk 6D88UOQbmAmAmCY8trcaFwc8ni25SI/eu5kMCDxKS6ci9E+NDGHFO2cNkiT1U7L/8moS 3I/Pl0oIobho42h+joo1vAD9KBGsGBAeeX4iaIHJ9h8U6oJA9Q9YNiKTcAslU0n73yOF Fldg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=84aCjuC9M4Y7E6k4BpfX06F1GA7SoTFWGROSgIxn3ys=; b=sHBSOhAo5LHkgjLfOzj0hgrf57T/UztyZ2DlB7tOczrMrlYK/U04D+lZ0uERMUR+ZE nBtWaCmL0rwhXSCdn7zMvHu1eWLWFx0SWyCDFgjidGuqkVY5JL0Az3luQjPgF5qNrmg9 staUZSkGKCQMPgoUfyU2Ca3vgPxjmnkHZJceQP1B990TR4gnSqMtoLWkr7qnO46IzO90 g6UJ+GSutctANPp9iukPL0eHaX8I4M2QbCdHPtCcBax4EQLKzgmVaZeqqcC1+azy0Jyy YqIoJIf5WY9mPLQP5BaPjz5Ul/1b39JfxjyEMbZQ9WiwTVYEfb36+84f9ro9m6/LrCPF IIgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P7fjBn9O; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id u33si1080320edc.244.2018.02.26.13.20.32; Mon, 26 Feb 2018 13:20:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P7fjBn9O; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 306A9C2215A; Mon, 26 Feb 2018 21:19:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 58FAFC21F32; Mon, 26 Feb 2018 21:18:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AB5B2C21F06; Mon, 26 Feb 2018 21:18:10 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by lists.denx.de (Postfix) with ESMTPS id 05953C21F31 for ; Mon, 26 Feb 2018 21:18:07 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id w77so22683855wrc.6 for ; Mon, 26 Feb 2018 13:18:07 -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; bh=cFuZilVNCUGeKGhd9/wfJPxNyd6e5Jt8MRW8da8wYYc=; b=P7fjBn9OxmuGaAGqgsooLsB5SQWNKFBVPhNWJUq+BLh/lZK0t12hPXtK7l8Yo4nuqG rro2DCGt0XBbvVDcx0AjIvgHtSoLHS1ZEcD8F0iVq3gKrIqRvm2WojQ7oRkVaHou3O+L 61aETwLVkOOphTjr1SkVxzUmnZT52CxLhGslQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cFuZilVNCUGeKGhd9/wfJPxNyd6e5Jt8MRW8da8wYYc=; b=swiYhZYQiBW55c15KzcaEVls+TBZKWC5sYrW7Nd2fGpiDl7xPkcYJW4QkvTU1k1ARr LB9/JQi8Df4rYGjyKb5XWys60Yj0a1PA0qFy6U+RUBkM/jG+vHF+EBRb3lZtXFZc6qUT LoG7ujOXBAE+HxsbzaeJou8au5LPOlOgZdu5pEMnrJ7HMBXgfCx0S04DiMOl1blNlxCK WBzLrDSjvlb+mO8MKK0Q4G7c5LIKh6bWVBkpnMsgcEFN+SUngoRg7z5Ms9QldHVxhggw QD2+lnt6//WaPp+s/6TRJPa83FeNSlTTQvx96jktW/NJhszalDixbFlkPmjWKQQ1xsYg suPg== X-Gm-Message-State: APf1xPA1OBihmoSHdy68cgbeI1MkEk0ZMQF4ibpXY93UKYsK6KBcoqB+ DtXwTBED75SVlgtbMozeyOp+jXmIW2Q= X-Received: by 10.223.130.76 with SMTP id 70mr10273929wrb.95.1519679886295; Mon, 26 Feb 2018 13:18:06 -0800 (PST) Received: from localhost ([195.238.92.76]) by smtp.gmail.com with ESMTPSA id e15sm9949135wmd.26.2018.02.26.13.18.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2018 13:18:05 -0800 (PST) From: Sam Protsenko To: u-boot@lists.denx.de Date: Mon, 26 Feb 2018 23:18:00 +0200 Message-Id: <20180226211801.16060-3-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180226211801.16060-1-semen.protsenko@linaro.org> References: <20180226211801.16060-1-semen.protsenko@linaro.org> Cc: Tom Rini , igor.opaniuk@linaro.org, Praneeth Bajjuri , Neil Williams Subject: [U-Boot] [PATCH 2/3] cmd: part: Extract common code to separate function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Refactor the code for "part start" and "part size" commands to avoid code duplication. Signed-off-by: Sam Protsenko Reviewed-by: Lukasz Majewski --- cmd/part.c | 61 +++++++++++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/cmd/part.c b/cmd/part.c index fd8825a7ec..ec791fdc5d 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -22,6 +22,11 @@ #include #include +enum cmd_part_info { + CMD_PART_INFO_START = 0, + CMD_PART_INFO_SIZE, +}; + static int do_part_uuid(int argc, char * const argv[]) { int part; @@ -108,7 +113,7 @@ static int do_part_list(int argc, char * const argv[]) return 0; } -static int do_part_start(int argc, char * const argv[]) +static int do_part_info(int argc, char * const argv[], enum cmd_part_info param) { struct blk_desc *desc; disk_partition_t info; @@ -138,7 +143,17 @@ static int do_part_start(int argc, char * const argv[]) return 1; } - snprintf(buf, sizeof(buf), LBAF, info.start); + switch (param) { + case CMD_PART_INFO_START: + snprintf(buf, sizeof(buf), LBAF, info.start); + break; + case CMD_PART_INFO_SIZE: + snprintf(buf, sizeof(buf), LBAF, info.size); + break; + default: + printf("** Unknown cmd_part_info value: %d\n", param); + return 1; + } if (argc > 3) env_set(argv[3], buf); @@ -148,44 +163,14 @@ static int do_part_start(int argc, char * const argv[]) return 0; } -static int do_part_size(int argc, char * const argv[]) +static int do_part_start(int argc, char * const argv[]) { - struct blk_desc *desc; - disk_partition_t info; - char buf[512] = { 0 }; - char *endp; - int part; - int err; - int ret; - - if (argc < 3) - return CMD_RET_USAGE; - if (argc > 4) - return CMD_RET_USAGE; - - ret = blk_get_device_by_str(argv[0], argv[1], &desc); - if (ret < 0) - return 1; - - part = simple_strtoul(argv[2], &endp, 0); - if (*endp == '\0') { - err = part_get_info(desc, part, &info); - if (err) - return 1; - } else { - part = part_get_info_by_name(desc, argv[2], &info); - if (part == -1) - return 1; - } - - snprintf(buf, sizeof(buf), LBAF, info.size); - - if (argc > 3) - env_set(argv[3], buf); - else - printf("%s\n", buf); + return do_part_info(argc, argv, CMD_PART_INFO_START); +} - return 0; +static int do_part_size(int argc, char * const argv[]) +{ + return do_part_info(argc, argv, CMD_PART_INFO_SIZE); } static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])