Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1302565ybz; Fri, 1 May 2020 19:36:02 -0700 (PDT) X-Google-Smtp-Source: APiQypIO4Oa8oe7CzD0H2qVWMfqrRNPJsf97GmI6LC+ElaMld//xDNhdLz01DWdtIAIzDhiXfhCn X-Received: by 2002:aa7:c7cb:: with SMTP id o11mr6142810eds.380.1588386962375; Fri, 01 May 2020 19:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588386962; cv=none; d=google.com; s=arc-20160816; b=v3GZf364Qivz+qMDFfCkLM33EKrAfQF0vVbhAkSmweRklMcVZz6EyAIhy+gAEXpSTA qebf3mBWPaHKoke++RCyMa7KRnpsG9cyfn9Tneq5LYjSXLVD3pN0oTQM0tf8fYfVpwTj 0lB5CvfNHMhz6BBSIWq5/ex2T1vQumM/i5/RgcKyU9Q8serFoVb4aJZd/ORJCQgO5jRW c20OlJK937OnD/qTz0hsFAEl6Asuu3x0CJj8cGLCzSADmzJEVPBGw8lvwMvylMdHBMlO x83xU06hf0aBDP0vT4C5LwAxlFpXWeNhG61coZOaBBd7y65/GDx2bvly4KxteCLF0B6c UVcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=iYIEoJGNhbKPN9zz/zszC6WL+W7rj9KlSLhmhiyLu+0=; b=p7dQmn4VNjtHGu/h9YK6Zdm6uAmYiAOFybYzRPeCPyZbSkoRLuvcFagSffWIhf4IO6 PCu8Rbh2VhojVAzhxUXwjx8CWtSGBqVu7VkmprJQrPp2PzSAT1fbhaA30OxKzYnxBVm1 zi0gerPvyAO74VGwYtF88MlxaFm/a0Pyi45aewvTRdRSaIDwYyLAVLgxWwNv+RqmV6m+ vnOPqyRnAzqK2t+mat0/ejDECM9m6KTewenTlAcztN0auKRIcHddppGccidqmCkyqyrw 4DIXJHSyX8Y1Iu3PQUG82t6QLfHCN6m4BFL6BTkI2+Y7XE0yVwhUpDDhHLMdMyUVQqfq utAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=vIbsxBNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si2838418edr.374.2020.05.01.19.35.39; Fri, 01 May 2020 19:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=vIbsxBNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727931AbgEBCdQ (ORCPT + 99 others); Fri, 1 May 2020 22:33:16 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:11939 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgEBCdQ (ORCPT ); Fri, 1 May 2020 22:33:16 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1588386795; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=iYIEoJGNhbKPN9zz/zszC6WL+W7rj9KlSLhmhiyLu+0=; b=vIbsxBNfH0vVAtaxN7vDocTQN1hNmYij4Cc6Z+D5NR9my5KWjPVfnVA6Vx+3I7W9KdOaIz+2 S5mXXpU/QtIoPx8NIeDQ2mR2kSsok6uYRkEOp3z7FTQZRG+cSU5p/Mx/PN9AxumbBcqh0isZ QmLU6u8hSdtoqay2cLp97II3Lo0= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5eacdbe0.7f7d8d8fd378-smtp-out-n02; Sat, 02 May 2020 02:33:04 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 88C5DC43637; Sat, 2 May 2020 02:33:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: bbhatt) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2C80AC433CB; Sat, 2 May 2020 02:33:03 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 01 May 2020 19:33:03 -0700 From: bbhatt@codeaurora.org To: Jeffrey Hugo Cc: mani@kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, hemantk@codeaurora.org, linux-kernel-owner@vger.kernel.org Subject: Re: [PATCH v3 9/9] bus: mhi: core: Ensure non-zero session or sequence ID values In-Reply-To: References: <1588193551-31439-1-git-send-email-bbhatt@codeaurora.org> <1588193551-31439-10-git-send-email-bbhatt@codeaurora.org> Message-ID: <612b805e217eebbafeaa080655af2fba@codeaurora.org> X-Sender: bbhatt@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-04-30 08:12, Jeffrey Hugo wrote: > On 4/29/2020 2:52 PM, Bhaumik Bhatt wrote: >> While writing any sequence or session identifiers, it is possible that >> the host could write a zero value, whereas only non-zero values are >> supported writes to those registers. Ensure that host does not write a >> non-zero value for those cases. >> >> Signed-off-by: Bhaumik Bhatt >> --- >> drivers/bus/mhi/core/boot.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/drivers/bus/mhi/core/boot.c b/drivers/bus/mhi/core/boot.c >> index 0bc9c50..c9971d4 100644 >> --- a/drivers/bus/mhi/core/boot.c >> +++ b/drivers/bus/mhi/core/boot.c >> @@ -199,6 +199,9 @@ static int mhi_fw_load_amss(struct mhi_controller >> *mhi_cntrl, >> mhi_write_reg(mhi_cntrl, base, BHIE_TXVECSIZE_OFFS, mhi_buf->len); >> sequence_id = prandom_u32() & BHIE_TXVECSTATUS_SEQNUM_BMSK; >> + if (unlikely(!sequence_id)) >> + sequence_id = 1; > > Seems like you could use prandom_u32_max(), and add 1 to the result to > eliminate the conditional. What do you think? > Agreed. Done using an internal macro in those places. >> + >> mhi_write_reg_field(mhi_cntrl, base, BHIE_TXVECDB_OFFS, >> BHIE_TXVECDB_SEQNUM_BMSK, BHIE_TXVECDB_SEQNUM_SHFT, >> sequence_id); >> @@ -254,6 +257,9 @@ static int mhi_fw_load_sbl(struct mhi_controller >> *mhi_cntrl, >> lower_32_bits(dma_addr)); >> mhi_write_reg(mhi_cntrl, base, BHI_IMGSIZE, size); >> session_id = prandom_u32() & BHI_TXDB_SEQNUM_BMSK; >> + if (unlikely(!session_id)) >> + session_id = 1; >> + >> mhi_write_reg(mhi_cntrl, base, BHI_IMGTXDB, session_id); >> read_unlock_bh(pm_lock); >>