From patchwork Wed Feb 1 12:47:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 93017 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2301239obz; Wed, 1 Feb 2017 04:49:07 -0800 (PST) X-Received: by 10.84.231.203 with SMTP id g11mr4227790pln.165.1485953347837; Wed, 01 Feb 2017 04:49:07 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b69si19054885pfk.235.2017.02.01.04.49.07; Wed, 01 Feb 2017 04:49:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750970AbdBAMtG (ORCPT + 5 others); Wed, 1 Feb 2017 07:49:06 -0500 Received: from mail-lf0-f45.google.com ([209.85.215.45]:33885 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750957AbdBAMtG (ORCPT ); Wed, 1 Feb 2017 07:49:06 -0500 Received: by mail-lf0-f45.google.com with SMTP id v186so227911708lfa.1 for ; Wed, 01 Feb 2017 04:49:05 -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=6vLsqCUbHYphiRmD21s24+pWS2qMkB6W425zsw1GkQs=; b=dtFvmhMy5WmSl28bQkXJPzINTIX8p9K5LIRenYU4FfwXclU/hQTv/CTY80A9gN1B3G 18dBvYhgjxa7c3pWoCBhCcKsJwfEMT8Dp4S+93DDF7NdhVCOxfuWjkT5Lh3eUIUir89v aIFDXrmCLXtJYTdy8vQCWmAVuUbf2zKovG/2M= 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=6vLsqCUbHYphiRmD21s24+pWS2qMkB6W425zsw1GkQs=; b=FcfQ5Dnvq1iy4leTzkFsey+TkE+BlpPCtqMyNfrvvizm2ZdiP+zpmE67jU/8dmj7Fh zf+m5ZdIuPH2GBB8Jg7MwiFzzQHzefLNBSOHvsD67tvKeV3EMKYu+1SwvBmJk+Gn+7ij C+Y+pzjgfxDK1weh4X+TJF2ZXSxZFUIVgvr85kaJKv71WXuX+AAAIULaVJPFKtMCF5Z9 yQFo3kf9vsU1AYclGjfqdgEIPDe+SabMLaz8q2OlFzj+omf9/gnrbsqzdEPj4Km4m8LV JQsaAjVA/8qPlmH09LP89CPUQT0j7VxMsqn5Isn9FmDI0yat/+n4zNo3/fR/HJTTuWas QLHQ== X-Gm-Message-State: AIkVDXKliYvtvRUOExIN38vfyKcdyyy0AOqmtda/c/xERapDciQUdEKBA1C1gQWJZAs0KIl4 X-Received: by 10.25.67.11 with SMTP id q11mr1033963lfa.139.1485953344725; Wed, 01 Feb 2017 04:49:04 -0800 (PST) Received: from gnarp.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t126sm5707754lff.31.2017.02.01.04.49.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Feb 2017 04:49:03 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Chunyan Zhang , Baolin Wang , Linus Walleij Subject: [PATCH 07/10] mmc: block: return errorcode from mmc_sd_num_wr_blocks() Date: Wed, 1 Feb 2017 13:47:57 +0100 Message-Id: <20170201124800.13865-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170201124800.13865-1-linus.walleij@linaro.org> References: <20170201124800.13865-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org mmc_sd_num_wr_blocks() has an interesting construction that saves one return argument by casting (u32)-1 as error code if something goes wrong. This is however a bit confusing when the normal kernel pattern is to return an int error code on success. So instead pass a variable "blocks" that the function can fill in with the number of successfully transfered blocks and return an integer as error code. Signed-off-by: Linus Walleij --- drivers/mmc/core/block.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 1ac7fec03c97..91d506b37024 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -768,7 +768,7 @@ static inline int mmc_blk_part_switch(struct mmc_card *card, return 0; } -static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) +static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks) { int err; u32 result; @@ -786,9 +786,9 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) err = mmc_wait_for_cmd(card->host, &cmd, 0); if (err) - return (u32)-1; + return err; if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD)) - return (u32)-1; + return err; memset(&cmd, 0, sizeof(struct mmc_command)); @@ -808,7 +808,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) blocks = kmalloc(4, GFP_KERNEL); if (!blocks) - return (u32)-1; + return -ENOMEM; sg_init_one(&sg, blocks, 4); @@ -818,9 +818,11 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) kfree(blocks); if (cmd.error || data.error) - result = (u32)-1; + return -EIO; - return result; + *written_blocks = result; + + return 0; } static int get_card_status(struct mmc_card *card, u32 *status, int retries) @@ -1581,9 +1583,10 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card, */ if (mmc_card_sd(card)) { u32 blocks; + int err; - blocks = mmc_sd_num_wr_blocks(card); - if (blocks != (u32)-1) { + err = mmc_sd_num_wr_blocks(card, &blocks); + if (!err) { ret = blk_end_request(req, 0, blocks << 9); } } else {