From patchwork Fri Nov 30 12:54:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 10706225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EA631057 for ; Fri, 30 Nov 2018 12:55:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F58F2F895 for ; Fri, 30 Nov 2018 12:55:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 836372FFF9; Fri, 30 Nov 2018 12:55:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A4E12F8B3 for ; Fri, 30 Nov 2018 12:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726070AbeLAAEK (ORCPT ); Fri, 30 Nov 2018 19:04:10 -0500 Received: from sauhun.de ([88.99.104.3]:58382 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbeLAAEK (ORCPT ); Fri, 30 Nov 2018 19:04:10 -0500 Received: from localhost (p54B334EC.dip0.t-ipconnect.de [84.179.52.236]) by pokefinder.org (Postfix) with ESMTPSA id A59282E3542; Fri, 30 Nov 2018 13:54:55 +0100 (CET) From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Avri Altman , Chris Ball , Wolfram Sang Subject: [PATCH mmc-utils] use proper type for RPMB blocks_cnt Date: Fri, 30 Nov 2018 13:54:47 +0100 Message-Id: <20181130125447.32218-1-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.11.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The JEDEC standard is confusing. The number of max blocks for reading RPMB is determined by CMD23 which can hold an unsigned int and not only u16. It is true that the current maximum is 64K of blocks, yet this may be extended in the future. Let's not apply a limit here which should be checked by the card. Signed-off-by: Wolfram Sang Reviewed-by: Avri Altman --- It is a bit academic, since we will be limited by MMC_IOC_MAX_BYTES in the kernel anyhow. Still, because this is a subtle issue, I think it is worth documenting the proper use. mmc_cmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 44623fe..69485e9 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2070,7 +2070,12 @@ int do_rpmb_read_counter(int nargs, char **argv) int do_rpmb_read_block(int nargs, char **argv) { int i, ret, dev_fd, data_fd, key_fd = -1; - uint16_t addr, blocks_cnt; + uint16_t addr; + /* + * for reading RPMB, number of blocks is set by CMD23 only, the packet + * frame field for that is set to 0. So, the type is not u16 but uint! + */ + unsigned int blocks_cnt; unsigned char key[32]; struct rpmb_frame frame_in = { .req_resp = htobe16(MMC_RPMB_READ),