From patchwork Thu Sep 24 01:30:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Grundler X-Patchwork-Id: 7253201 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F19739F380 for ; Thu, 24 Sep 2015 01:30:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECC502042B for ; Thu, 24 Sep 2015 01:30:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C514C208AC for ; Thu, 24 Sep 2015 01:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756147AbbIXBam (ORCPT ); Wed, 23 Sep 2015 21:30:42 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36562 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310AbbIXBal (ORCPT ); Wed, 23 Sep 2015 21:30:41 -0400 Received: by pacgz1 with SMTP id gz1so6725340pac.3 for ; Wed, 23 Sep 2015 18:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=VIZSaM9Gc1ZOWLBfElkVpTVYbLGrYFu+YkL7tizFz/w=; b=FxhXKwqvrF931PSUobkSBWy/+fsqNAIptOKPrrkBkrg3NO+JX4PXYryTQvdk+6Lbsq +AMiqSlbECRZB4JgzZkq46GMWAmAyPp8zNweNE5jmUzMZ/hlThgSNir/6Llt4iQ3Kewb 28COy5uoLc15yZP6e8qIaz1qV/HnhCNm+GPm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VIZSaM9Gc1ZOWLBfElkVpTVYbLGrYFu+YkL7tizFz/w=; b=CXmvSasjF9n6OSTlvJr/5Q9/e5loxEVJsJklQfjp3UtRMEKzzuKhQFyGq0w+jvOCH8 zAOXLNCKOGIIdStKK7HWQ7CKdKbPBBTiXRtaDOZwNE2oC1kn3LGhu2j3+FWR09Osa58n RTCazovi3NHGF4Q5Dn04Z3vdYXnk0zVA5TTCP6UF5Lju+fj4061mj5f6RIcA7PQgcCl6 9DiI9GPsL9s3IPzob/tggItjXaxWDiupMaMPCghyiaa7KkIMUBmEZpGEyfepC44jfhI9 wmZFOM/so1mclWpQD+X1gwdRqdUfE8h6FCtorl/osuwxZeTNjJ3ZbKMwTNAE3vSJtJQR 9zYg== X-Gm-Message-State: ALoCoQn8kWQBPdWlVuum4fdgLKcSr2B9IC1uvPJsnB7CgNy4g2XsEYJTgzG9gWE71/Hnj+Y7drXg X-Received: by 10.66.190.135 with SMTP id gq7mr41341261pac.65.1443058241089; Wed, 23 Sep 2015 18:30:41 -0700 (PDT) Received: from firesword.mtv.corp.google.com ([172.22.64.201]) by smtp.gmail.com with ESMTPSA id y10sm10285774par.34.2015.09.23.18.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Sep 2015 18:30:39 -0700 (PDT) From: Grant Grundler To: Ulf Hansson Cc: linux-mmc , linux-kernel@vger.kernel.org, Jon Hunter , Hyung Taek Ryoo , Gwendal Grignou , Grant Grundler Subject: [PATCH] mmc: block: copy resp[] data on err for MMC_IOC_MULTI_CMD Date: Wed, 23 Sep 2015 18:30:33 -0700 Message-Id: <1443058233-2370-1-git-send-email-grundler@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP MMC_IOC_CMD and MMC_IOC_MULTI_CMD ioctl() code currently bails on any eMMC errors. However, in case there is any resp[] data, we should attempt to copy resp[] back to user space. The user app can then determine which command(s) failed in the MMC_IOC_MULTI_CMD case AND/OR report better diagnostics in both cases. Gwendal Grignou provided the idea and it was previously implemented and tested on v3.18 ChromeOS kernel: https://chromium-review.googlesource.com/#/c/299956 Signed-off-by: Grant Grundler Reviewed-by: Hyung Taek Ryoo Reviewed-by: Gwendal Grignou Tested-by: David Riley --- I believe the patch applied correctly to Ulf's mmc.git on linaro.org. I would have warm fuzzies if Jon or Hyung (Nvidia) could review/test this. I made one change from the chromium.org version: initialize err and ioc_err to zero in mmc_blk_ioctl_cmd() drivers/mmc/card/block.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index f6acf0f..23b6c8e 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -595,7 +595,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, struct mmc_blk_ioc_data *idata; struct mmc_blk_data *md; struct mmc_card *card; - int err; + int err = 0, ioc_err = 0; idata = mmc_blk_ioctl_copy_from_user(ic_ptr); if (IS_ERR(idata)) @@ -615,19 +615,18 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, mmc_get_card(card); - err = __mmc_blk_ioctl_cmd(card, md, idata); + ioc_err = __mmc_blk_ioctl_cmd(card, md, idata); mmc_put_card(card); - if (!err) - err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata); + err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata); cmd_done: mmc_blk_put(md); cmd_err: kfree(idata->buf); kfree(idata); - return err; + return ioc_err ? ioc_err : err; } static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, @@ -637,7 +636,7 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, struct mmc_ioc_cmd __user *cmds = user->cmds; struct mmc_card *card; struct mmc_blk_data *md; - int i, err = -EFAULT; + int i, err = 0, ioc_err = 0; __u64 num_of_cmds; if (copy_from_user(&num_of_cmds, &user->num_of_cmds, @@ -672,22 +671,14 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev, mmc_get_card(card); - for (i = 0; i < num_of_cmds; i++) { - err = __mmc_blk_ioctl_cmd(card, md, idata[i]); - if (err) { - mmc_put_card(card); - goto cmd_done; - } - } + for (i = 0; i < num_of_cmds && !ioc_err; i++) + ioc_err = __mmc_blk_ioctl_cmd(card, md, idata[i]); mmc_put_card(card); /* copy to user if data and response */ - for (i = 0; i < num_of_cmds; i++) { + for (i = 0; i < num_of_cmds && !err; i++) err = mmc_blk_ioctl_copy_to_user(&cmds[i], idata[i]); - if (err) - break; - } cmd_done: mmc_blk_put(md); @@ -697,7 +688,7 @@ cmd_err: kfree(idata[i]); } kfree(idata); - return err; + return ioc_err ? ioc_err : err; } static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,