From patchwork Tue Jun 9 17:45:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 224650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35623C433E1 for ; Tue, 9 Jun 2020 18:02:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09C50206D5 for ; Tue, 9 Jun 2020 18:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591725774; bh=6YPxQIpnHA4tJL9vOwIld7dOcuszsw2Lm6F7R0UTo0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oLwKnkgWqKvkn/uUnquD7C762uVcnCCaIKoXStzF+FEIT4LH5HAuDaMutvA6pSzpN csj3OrLFnYLA+zwU31y5i7166RQmuRue4RguR+YY0Ye7UHsbxV3/WkC67JBO/pQT4D oVtX8tWj5q7GLu9Q6JBD4i0ZHovk3mmAOh2aP1e0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733003AbgFIRxN (ORCPT ); Tue, 9 Jun 2020 13:53:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:43972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731732AbgFIRxK (ORCPT ); Tue, 9 Jun 2020 13:53:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7BC492074B; Tue, 9 Jun 2020 17:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591725189; bh=6YPxQIpnHA4tJL9vOwIld7dOcuszsw2Lm6F7R0UTo0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0RDv4TuJp0SOuvmx4anxA0kTj72aoIVfFKf73sRo/P1/7tHEpnl27ja+RMSpa+NJA p7/I7dRWmn5YrXwJYa/l0Mc2tbnY7ty0xu2p+mSOkaJm28gGwnZHhk+gCNVTUcDlx4 PaUgaexSH5NSMKmSs/rgO1JeZ43w0q0eyQrHISVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dinghao Liu , Bin Liu Subject: [PATCH 5.4 21/34] usb: musb: Fix runtime PM imbalance on error Date: Tue, 9 Jun 2020 19:45:17 +0200 Message-Id: <20200609174055.288728754@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200609174052.628006868@linuxfoundation.org> References: <20200609174052.628006868@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dinghao Liu commit e4befc121df03dc8ed2ac1031c98f9538e244bae upstream. When copy_from_user() returns an error code, there is a runtime PM usage counter imbalance. Fix this by moving copy_from_user() to the beginning of this function. Fixes: 7b6c1b4c0e1e ("usb: musb: fix runtime PM in debugfs") Signed-off-by: Dinghao Liu Cc: stable@vger.kernel.org Signed-off-by: Bin Liu Link: https://lore.kernel.org/r/20200525025049.3400-7-b-liu@ti.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_debugfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/usb/musb/musb_debugfs.c +++ b/drivers/usb/musb/musb_debugfs.c @@ -168,6 +168,11 @@ static ssize_t musb_test_mode_write(stru u8 test; char buf[24]; + memset(buf, 0x00, sizeof(buf)); + + if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) + return -EFAULT; + pm_runtime_get_sync(musb->controller); test = musb_readb(musb->mregs, MUSB_TESTMODE); if (test) { @@ -176,11 +181,6 @@ static ssize_t musb_test_mode_write(stru goto ret; } - memset(buf, 0x00, sizeof(buf)); - - if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) - return -EFAULT; - if (strstarts(buf, "force host full-speed")) test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS;