From patchwork Thu Nov 22 19:13:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 201141 X-Patchwork-Delegate: afleming@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 45DAE2C008C for ; Fri, 23 Nov 2012 06:15:56 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1E0344A0B6; Thu, 22 Nov 2012 20:15:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TbZqqDr7-7wc; Thu, 22 Nov 2012 20:15:53 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8AD8E4A08B; Thu, 22 Nov 2012 20:15:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 176944A050 for ; Thu, 22 Nov 2012 20:14:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NPAU8Z0ZpE2q for ; Thu, 22 Nov 2012 20:14:52 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-wg0-f74.google.com (mail-wg0-f74.google.com [74.125.82.74]) by theia.denx.de (Postfix) with ESMTPS id 0C6E54A02D for ; Thu, 22 Nov 2012 20:14:47 +0100 (CET) Received: by mail-wg0-f74.google.com with SMTP id dt14so598706wgb.3 for ; Thu, 22 Nov 2012 11:14:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=1iG0f5wsxmMssHU+kMqb1NZ6KL6rtNUmPCBscpPxJY8=; b=VL5xjIDY9EX1nbDWzj59UDi6ku7048gy932inIotU3ExRmlFOYLknsssxtrRfG3QVN sERUjQo8BtHlOQ/wDCrVVSOG8lhp6vcOodiUHvPG4Pw6S6KnfeWXbC0A5wTf/6pIyu+8 fk8ikTDHTwhMVks9gQPDj6sioXaeQW/cppw6cUQGbFbUXLVaYg+c+tOMWB2VtBsec8dB dxzMyET1+yO8OU4l6UJq0s9h/1ldyAUrzyiz/nDBzbBfVJDmQCRcs1+h2yKvaFWbQp2L m1ZkaINtkYI7Chb2nIiGCoTctb2GhvrmQlOoomh8Oem72GkjuUJ5MbFqeVTDgbT+pi+V 0qsQ== Received: by 10.14.204.3 with SMTP id g3mr2178161eeo.7.1353611687267; Thu, 22 Nov 2012 11:14:47 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id u8si1007928een.1.2012.11.22.11.14.47 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 22 Nov 2012 11:14:47 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id D660F200057; Thu, 22 Nov 2012 11:14:46 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 90F151608F0; Thu, 22 Nov 2012 11:14:46 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 22 Nov 2012 11:13:00 -0800 Message-Id: <1353611587-18186-17-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1353611587-18186-1-git-send-email-sjg@chromium.org> References: <1353611587-18186-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQnHdh5YUVYfoWyLwEHW1eJTqaRLzK95OmyJ+murtUsE4tuUH+1rQc/UtgGMeaSMTM4ZvwBmy4DwD2yROy3dbgWVEjagrT4qgCy+z5JLG68ElzSyyaXxFgQgnxr2tnF73vN5GxRWvohQ+ZApWm5mJZxSVW2DwSxzXjXk6xT4LMD6ZaBQS08bPl+JcB1tpFzo9ggo6Cio Cc: Tom Rini , Andy Fleming , Taylor Hutt Subject: [U-Boot] [PATCH v2 16/23] mmc: Fix incorrect handling of 'read' & 'write' commands X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Taylor Hutt If a malformed 'read' or 'write' command is issued, the Sandbox U-Boot can crash because the command-handling code does no error checking on the number of provided arguments. This change makes the mmc 'erase', 'read' and 'write' commands only function if the proper number of arguments are supplied. Also puts the else assignment at the beginning fo the if() statement to shortens the generated code. This removes an unnecessary jump from the generated code. Signed-off-by: Taylor Hutt Signed-off-by: Simon Glass --- Changes in v2: None common/cmd_mmc.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 4c19df7..7dacd51 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -250,14 +250,13 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } - if (strcmp(argv[1], "read") == 0) + state = MMC_INVALID; + if (argc == 5 && strcmp(argv[1], "read") == 0) state = MMC_READ; - else if (strcmp(argv[1], "write") == 0) + else if (argc == 5 && strcmp(argv[1], "write") == 0) state = MMC_WRITE; - else if (strcmp(argv[1], "erase") == 0) + else if (argc == 4 && strcmp(argv[1], "erase") == 0) state = MMC_ERASE; - else - state = MMC_INVALID; if (state != MMC_INVALID) { struct mmc *mmc = find_mmc_device(curr_device);