Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp2871ybr; Thu, 21 May 2020 22:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5jWGMuXlQG1vwPNBXrbJeMhTukzH3TKMSsnw7+jkKvPqQqcmTEj0jmB+TQTISBGcJsyJv X-Received: by 2002:a50:88c6:: with SMTP id d64mr1740042edd.324.1590126447370; Thu, 21 May 2020 22:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590126447; cv=none; d=google.com; s=arc-20160816; b=yS1+fXgESlwzjfxsbjlF2fCg5OBemCtOMCGL1mQeFGcj5iiU+hqZcDNsLvWBCMndTP 9dZLDiPhb+fFdm1pW5+34s59QrkFRrbZwND2fe1znmQucM2jDniGhOcSOZNXB1tKwDHl 05YcZ8m3ce7c0DFMzLVIqp9kUrgjNDDHx219p5JjxNTZ1nOkD0GGPBzMi9zc5k0Kawnl ITFYS1v+zg2gIIxcWEGIzihzKtuA5nx5gQDW2yHhk8oQKe7TtV0jBYHICF7E1m6Dwfya LANRu0iKl/J/AxV5DTTt0tpkguNcJcZutfsJ5CMzFX+9uKXcVxPWmE0mHiyR2ns4dqlu 0biQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qrnE5k4mKfFtZEvCdab4wdZWWhI81QSDwMrkWjHvt+I=; b=kIIv2dYVt9CLwHkuPLAW0uqwj9Gb/ArqBcaxB5ZvRvoTqcprObA2KDQV2XP5oKAPkH HRHexj91TyIPTXaKxOumgtICZd5kbPo731KsTik9schtYAbFFiZXzXDI1mAruV+Cv7Ia s7EZWPBsIrGMKgqgJs/8kdJGDMdjXxV0ra2yYVS/OSLPg5TUpXBgGmgWlIDjVGgmsjXM EazGq7sp39EBquQHB6inWSLXTu2LIPaRkbQwBISNWPFlbZIIAb05g6TZjTBmNigZesUI HTNO2qE+fugEotrGG/CBokf5hSZwPUNUKgb5g1vZ4Odk499BXaRk0kZnp06LBeMSmtF6 L/GQ== ARC-Authentication-Results: i=1; mx.google.com; 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 s3si2319358eds.446.2020.05.21.22.47.04; Thu, 21 May 2020 22:47:27 -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; 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 S1728137AbgEVFmy (ORCPT + 99 others); Fri, 22 May 2020 01:42:54 -0400 Received: from spam.zju.edu.cn ([61.164.42.155]:25312 "EHLO zju.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725894AbgEVFmy (ORCPT ); Fri, 22 May 2020 01:42:54 -0400 Received: from localhost.localdomain (unknown [222.205.77.158]) by mail-app3 (Coremail) with SMTP id cC_KCgCXn4tNZsdelIDvAA--.30245S4; Fri, 22 May 2020 13:42:41 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn, kjlu@umn.edu Cc: Bin Liu , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v3] usb: musb: Fix runtime PM imbalance on error Date: Fri, 22 May 2020 13:42:35 +0800 Message-Id: <20200522054235.7944-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgCXn4tNZsdelIDvAA--.30245S4 X-Coremail-Antispam: 1UD129KBjvJXoW7ur47ur4rtr4xAF48tF4fKrg_yoW8GF47p3 W09FW3KrW8tayfAF1qva1kXF95X39a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-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Dinghao Liu --- Changelog: v2: - Move copy_from_user() to the beginning rather than adding pm_runtime_put_autosuspend(). v3: - Add missing changelog information. --- drivers/usb/musb/musb_debugfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c index 7b6281ab62ed..30a89aa8a3e7 100644 --- 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(struct file *file, 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(struct file *file, 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; -- 2.17.1