From patchwork Wed Dec 7 01:01:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9463685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A381060459 for ; Wed, 7 Dec 2016 01:01:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 946CB284EE for ; Wed, 7 Dec 2016 01:01:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 891FB284FA; Wed, 7 Dec 2016 01:01:51 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 289DA284EE for ; Wed, 7 Dec 2016 01:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752529AbcLGBBu (ORCPT ); Tue, 6 Dec 2016 20:01:50 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:36580 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751527AbcLGBBu (ORCPT ); Tue, 6 Dec 2016 20:01:50 -0500 Received: by mail-pg0-f50.google.com with SMTP id f188so154629976pgc.3 for ; Tue, 06 Dec 2016 17:01:49 -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; bh=1TUYqLJDOf88TiedVnvUuntK1cRfW97hLzFmDuiE3SY=; b=Dq7SX/seZ17FhGWPra4Hzw1ch86c7SP/8Ixdg3H3QEcou92WTCoQ7w7FLfRt2JKm+2 Rs5x5k/Cq+g237YNWB0H9K3Sly64uEXgCUFYX1IXKjArG1rYq1B9fMBuqlo52fAzqye9 VQ/+lrZAY0hZibz/+qnuafYH2BDOyX+dE3HDM= 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=1TUYqLJDOf88TiedVnvUuntK1cRfW97hLzFmDuiE3SY=; b=EBL9UQcHtbEr1VuNzv3MWld4Pc/EeMMhXeudkdSzIdM/X/3CLwvPitbCrvou/o0nqN pNDIq96fa74oPBx62EyBJXfD4SoEHm7r4vyzfcDHPc44+c5I8xjz95UcXLEaZ50Hhahb 0wVm16Sdwvak/heTGyHRzg4WKXCg99RXjXeM5OU3UxF/lwfJpuq5MYxBWRQq5zuF4GT9 E/RCNuWCFacd6/Vrlo0NXEniql0aOAuLvvGHTXzGZv2hKgAoy/DrKASvwhOA5KCptFPg 4lBgvIQYHpXgAWMiFZyKlYR2fZ7kJTPscL7FsazlN7p6tSatYFW4qoLSgEzIkkxXFCWL 8YaA== X-Gm-Message-State: AKaTC00OOv1+QKJnWP126Oev5pedNKw4c7UaS6R/oLB9wPBx+FB8ssPWZJ21ceNyxO0mhck8 X-Received: by 10.99.127.16 with SMTP id a16mr88599846pgd.60.1481072509354; Tue, 06 Dec 2016 17:01:49 -0800 (PST) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id 1sm37680667pgp.1.2016.12.06.17.01.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 17:01:48 -0800 (PST) From: Bjorn Andersson To: Ming Lei , "Luis R. Rodriguez" , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org Subject: [PATCH] firwmare: Correct handling of fw_state_wait() return value Date: Tue, 6 Dec 2016 17:01:45 -0800 Message-Id: <1481072505-2732-1-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When request_firmware() finds an already open firmware object it will wait for that object to become fully loaded and then check the status. As __fw_state_wait_common() succeeds the timeout value returned will be truncated in _request_firmware_prepare() and interpreted as -EPERM. Prior to "firmware: do not use fw_lock for fw_state protection" the code did test if we where in the "done" state before sleeping, causing this particular code path to succeed, in some cases. As the callers are interested in the result of the wait and not the remaining timeout the return value of __fw_state_wait_common() is changed to signal "done" or "error", which simplifies the logic in _request_firmware_load() as well. Fixes: 5b029624948d ("firmware: do not use fw_lock for fw_state protection") Signed-off-by: Bjorn Andersson Reviewed-by: Daniel Wagner Acked-by: Luis R. Rodriguez --- The regression was introduced in next-20161201 drivers/base/firmware_class.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index eb95cf7c3b28..4497d263209f 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -127,7 +127,7 @@ static inline bool __fw_state_is_done(enum fw_status status) return status == FW_STATUS_DONE || status == FW_STATUS_ABORTED; } -static long __fw_state_wait_common(struct fw_state *fw_st, long timeout) +static int __fw_state_wait_common(struct fw_state *fw_st, long timeout) { long ret; @@ -136,8 +136,10 @@ static long __fw_state_wait_common(struct fw_state *fw_st, long timeout) timeout); if (ret != 0 && fw_st->status == FW_STATUS_ABORTED) return -ENOENT; + if (!ret) + return -ETIMEDOUT; - return ret; + return ret < 0 ? ret : 0; } static void __fw_state_set(struct fw_state *fw_st, @@ -1017,14 +1019,11 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, timeout = MAX_JIFFY_OFFSET; } - timeout = fw_state_wait_timeout(&buf->fw_st, timeout); - if (timeout == -ERESTARTSYS || !timeout) { - retval = timeout; + retval = fw_state_wait_timeout(&buf->fw_st, timeout); + if (retval < 0) { mutex_lock(&fw_lock); fw_load_abort(fw_priv); mutex_unlock(&fw_lock); - } else if (timeout > 0) { - retval = 0; } if (fw_state_is_aborted(&buf->fw_st))