Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp412034pxb; Tue, 12 Apr 2022 04:58:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAorBVWDVRSDYiWm+5RoLc9HDp0kf/0uO9wAlG5W9XiPG1v3cmgQmP1cSuLXHzSAmxjq7t X-Received: by 2002:a05:6a00:d54:b0:505:79bd:6799 with SMTP id n20-20020a056a000d5400b0050579bd6799mr22571132pfv.72.1649764701934; Tue, 12 Apr 2022 04:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649764701; cv=none; d=google.com; s=arc-20160816; b=KsVTQaGx24iKRKCrieBbHPbVsEe87kN1LWC4hKt58ILQUwfjsRGl/Xtt8DURoA4TPR RF3hGXKcLW0sqo/mij9sIdkLbrUWEF6+0+KZx7z9nDvdp3saL1Ja9V02nlMSgdSPkOWL 2E/IWg+mpqFOCLURUxHY3lyiSxyOquVIwLByYieSmRS+cRQBc6bkTXaxF3RCMiirIJGP bxqWA/oESuqsfI1bAWA7BvXSLl6Fr5Mk3DO1w2Zc0TQkJWQRCMIYTfTkoq9WSkQDXCGs 761e73SUXSS6Ns1JXkrSjM5h0Wxz+YC2HJFs+/elSJIJWgQxy+hvpodM0qZrsrSar1n7 0VOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=dVMawSZQEIcAON9OuUYu/RF6i61CbmAB/0P2rS+Niq0=; b=h/1d1bVFuNG7520XE+M5YQVKZoWW2u+NZFmjN3w4/PdMyJstX/Zig3gyx2zH3bxI3N blCYbucJ0fTyGbIzp3/DdrsESwvixFFRVrrfAjj/u62GHvPSDpNMo6DonKYheKDEBIqo H5wWJZR2U6vMluXVlYX8a3i8dlzR0MpSAV44RNPdQvvj7Lfa5F3Ol7W4KbrYyr8bGWmU EMtKcvnO0Z3Tk5V4fpnHn2u19LNdgwDeCfJPEA1mKxYiRBDRYf9p5rPSpHQvzUUS/tK/ rk9TkuvzF77MgSsCBPQA33aVL+61RZljBJ7BhHlPZQ9ue5wm/z2ndzETHJbhGk974l+2 taJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZnVU6Vdi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a170903234700b00153b2d16404si12911032plh.12.2022.04.12.04.58.08; Tue, 12 Apr 2022 04:58:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZnVU6Vdi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345724AbiDKKsA (ORCPT + 99 others); Mon, 11 Apr 2022 06:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345727AbiDKKr6 (ORCPT ); Mon, 11 Apr 2022 06:47:58 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CF31704D for ; Mon, 11 Apr 2022 03:45:44 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id md4so6592223pjb.4 for ; Mon, 11 Apr 2022 03:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=dVMawSZQEIcAON9OuUYu/RF6i61CbmAB/0P2rS+Niq0=; b=ZnVU6Vdi4CL+JdxE8NFBbrd2sFXyWSxK0EFH++TjTRbG0/Ywgy/TvN0oHQ3T5rfWcE JASXMyls9+hBrh1Nfos+PNyEVSVcSZdsydGO8g3MGdIUcatsCtr6fU2sJnhfjh/bf1CR xXh3fB/W7HafnoxbTQbsipPRGjD1rMWaGmeQ1NLhCMsauZfie2C6vjbC4MOoVaVGoyRW k3pm9Ne7QviKJeFFn5/d7audwxNXD/hi2con3rOImdwR6Qu16+rfzjzqahPzEcyNMS3x yzXSJu3B0MR0TkTboEiPf4FV0J5umSUb/aLoDh3/oxxaL+JZUtzuFoDZDuEZTxJXGaf/ 6oSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dVMawSZQEIcAON9OuUYu/RF6i61CbmAB/0P2rS+Niq0=; b=33hVVfsMZ1m/vAcT9fVsimKO7VNCyEnFUMpr8b0nVjG6cr0QYGeNXFF01J/xJAE+kG WlTXKHg7ITtjADxQeC+sXYg4XBDaD/9fVIdSTGJYWw2wOZWfPWpXfL4/cXPS2zO2eijo gv/QsCzt5p1nPF2H5vEHu98i/HyND2GLY+WewcCceXFNsNmF6LOcoMXNy8yEKdGLYQzS 2SRDNJ/W3ScR3nuZP5uGsKynBC4szPNL3IBRMw9hvBdVaYc+58cEpOeHGzmi+UCbxjdh xNn0wvNx+raojx8HhzISSLg2Vxee2JD/R2vpj/Uinr3t+ecuEbkLeTOpzOLtxlSwrVK2 SMGw== X-Gm-Message-State: AOAM533zkqpCcHgefmx16hF64YhdEFes4dHJRqfMe0F9gfDEqxam+wi8 cxWWUSZVLLG6vIzp5OMysuSBp5NByHZoDM68 X-Received: by 2002:a17:902:c94e:b0:156:498c:f02b with SMTP id i14-20020a170902c94e00b00156498cf02bmr32159946pla.49.1649673944101; Mon, 11 Apr 2022 03:45:44 -0700 (PDT) Received: from localhost.localdomain ([159.226.95.43]) by smtp.googlemail.com with ESMTPSA id s26-20020a65645a000000b0039cc7a70728sm12122565pgv.5.2022.04.11.03.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 03:45:43 -0700 (PDT) From: Miaoqian Lin To: =?UTF-8?q?Marek=20Beh=C3=BAn?= , Arnd Bergmann , linux-kernel@vger.kernel.org Cc: linmq006@gmail.com Subject: [PATCH] firmware: turris-mox-rwtm: Fix return value check of wait_for_completion_timeout Date: Mon, 11 Apr 2022 10:45:38 +0000 Message-Id: <20220411104539.17971-1-linmq006@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wait_for_completion_timeout() returns unsigned long not int. It returns 0 if timed out, and positive if completed. The check for <= 0 is ambiguous and should be == 0 here indicating timeout which is the only error case Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Signed-off-by: Miaoqian Lin --- drivers/firmware/turris-mox-rwtm.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index c2d34dc8ba46..5040b81d7849 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -193,15 +193,16 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) struct armada_37xx_rwtm_tx_msg msg; struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply; int ret; + unsigned long timeout; msg.command = MBOX_CMD_BOARD_INFO; ret = mbox_send_message(rwtm->mbox, &msg); if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); + if (timeout == 0) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); if (ret == -ENODATA) { @@ -235,9 +236,9 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); + if (timeout == 0) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); if (ret == -ENODATA) { @@ -264,6 +265,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm) { struct armada_37xx_rwtm_tx_msg msg; int ret; + unsigned long timeout; msg.command = MBOX_CMD_GET_RANDOM; msg.args[0] = 1; @@ -274,9 +276,9 @@ static int check_get_random_support(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); + if (timeout == 0) + return -ETIMEDOUT; return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval); } -- 2.17.1