From patchwork Mon Aug 29 13:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 12957781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D338DECAAD2 for ; Mon, 29 Aug 2022 13:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbiH2NLU (ORCPT ); Mon, 29 Aug 2022 09:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbiH2NLB (ORCPT ); Mon, 29 Aug 2022 09:11:01 -0400 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00047.outbound.protection.outlook.com [40.107.0.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 982F82B254 for ; Mon, 29 Aug 2022 06:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gEmuE0aDgHO0G3tP5S/1xH9ID2NJ5epEkly55zPt5bJqZIec97JV1yOgo5wP83DPnx/kll+ItAYWXAJzmKmgeEqmifZvXQpJJAqj2cUwbBE0QjVs0EYKDUFE7tBC9ms6GJx+JF425gRsjJfxvgXHzQBSzfXAwq7kg3jajcofF8+s/hhkCSZzH6r6AyUhv/1JRWFnsu8ZT8wJtPp1qPWbshkzNBUvfUQk1cpdYcc7WU8ww4AGcgy4egwgXnHPpqk1RmmNxnn6EedkcwTGg0+uA+5eLgK9ZbsMw2csx3AIs6OhDs052L0nh83q/PXZxaP4TdRhqrXMpyvkUEnDc2Icyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jiGzbnF5qPoVlvtGtkCZU7YtudIXypx7WZZ3CKPIYHE=; b=WNlsrhf68YTuUE5rb/uMjRv5moM2vx/ZWabekXxioij/kfRjsLMKXrTO16uJ3Cr0qjnaJPKflc2/Lz2gqZ68pC94ihC+jbVWeRnt4qVmGkhTyXJGyxrdtUBFiVYOx5K2BUG/q/rztuX39UACCmcklrfqUvJX5trmAFxHZCgPvGp3Ibs7UCNgrI+3HWhlRcs8Nwrm+VWTCpdsBNxqD1SGP0T+/79RMgiSOoELyc0L/u9JZvhg6wpFdl0LqdIXlH+uhVplEYUzJq2unUILXREiDHSwLK8bg7sIk6dVaFGVyHVsyZgOT2eVv+VA2uNkmQqbUFSHnn0LdfjNd8WG17TxMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jiGzbnF5qPoVlvtGtkCZU7YtudIXypx7WZZ3CKPIYHE=; b=w3/aLYJuRFh0EyaH6Eu7h+lS9XcbD1tvqlD9X30YqR19UljtdNmxEwyk1VFNqvuktZoCMhrJa0fr+Izm2L/CS964I0bA2tjCb9DErMlN8fywkxUf8OHUnsHmyz6GQcEEsY1c8v7d5qwq91cGtcN16DZsubLriHU194uQYWWB3TQ8i5kaig9CfbEjJhEmfBD8Z/rvGqlR86itpHmnZtkVnG7272KQVeOsXPEBv+9TDQ4DhAm+JnURhiuAbSMKeBUuBPo6KcYr5FbZyrz329mjaRn8LtV5s1pkGFgPgozUN3YudOvp0V9hdFsxFcyynlqoHD+2RbIu65Yfynq9IRdsyA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB7104.eurprd04.prod.outlook.com (2603:10a6:800:126::9) by DB6PR0401MB2583.eurprd04.prod.outlook.com (2603:10a6:4:37::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Mon, 29 Aug 2022 13:10:03 +0000 Received: from VI1PR04MB7104.eurprd04.prod.outlook.com ([fe80::b083:534b:70ae:416a]) by VI1PR04MB7104.eurprd04.prod.outlook.com ([fe80::b083:534b:70ae:416a%2]) with mapi id 15.20.5566.021; Mon, 29 Aug 2022 13:10:03 +0000 Message-ID: <78712d64-7bac-cc2f-4a99-52e35d12f46f@suse.com> Date: Mon, 29 Aug 2022 15:10:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US To: Dmitry Osipenko Cc: Peter Chen , USB list From: Oliver Neukum Subject: Cleaning up bf88fef0b6f1 ("usb: otg-fsm: Fix hrtimer list corruption") X-ClientProxiedBy: FR0P281CA0006.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::11) To VI1PR04MB7104.eurprd04.prod.outlook.com (2603:10a6:800:126::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0aab5493-443b-4bcf-1694-08da89bfc8de X-MS-TrafficTypeDiagnostic: DB6PR0401MB2583:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6WuaMz/zlzS1cay1R6xHdrMeUNT5w0TPQLW0E6fICFUvVFKG1zFC6QezI2su1GgU2F5BThZyn4ypYWMXnq7Qc1MdXY+HE4lNhNf+EvE+DxLNPW0NGlvUroVUfIQELMdck8ssXYDfEFK/DJHn2kNhR25Tg7f3Wt7xK8iId5X4sBbT0k6lwbGAHGV/I4SdF+7kbwlheUxDQGQOv52HxjwtIu0hlqsYVdCHIaknytRw98JG/48twqzUmX/WClF9wuTZDKzvOWu9j5F3qPGmj+DTmPMUVA0UA1S2nX4jnyfFzTh0lH8suoggxHxNEsnsy0K+vlAXA7FMB+OibhXVB7R9k5JktjDOby1VDb6mNHt3nz4mh6L2CtsUT/VapiHSatkc15Nr+cI1Kz86rFt2j4eXtk041soH6Dxr16HzfDlevNUTH0L9FVxYM+nKD7Vj8JoaU6073EuvMArtID9jnrOfYgyIDpqZ4CQoR1HjpTIqyeJZkTyko6rnC0fDdblUasAmcffbdvsx2HFiUwCmILgIJd5YjklKwG504HHMxFD9IHfBbOvMClj1SyS9dJCDrgLdfRsv1+bf4lFrOQUv7J3bqWYgUESRWlSPkObIaRhqHg6AUcTUZaArNIPd+1rcib5L83nTFrJ7ZGqZfiBkQCABTR0pIdWbetXa2B9IX1q3w5PEIHbubvV52HLqOJvBGY99uTytHdNaCxJpGDCcp2Nw5KryODX6Q+ltDnUGJWb9Zu1Kbkx88xUJAnDhRdQGyplU7J7horjKqVgnqQ/uKTxpWycdf5MEAPI8UhEhFi840nU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB7104.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(366004)(39860400002)(136003)(346002)(396003)(376002)(8676002)(66946007)(66556008)(66476007)(4326008)(316002)(54906003)(6916009)(31696002)(31686004)(6486002)(86362001)(5660300002)(8936002)(478600001)(235185007)(41300700001)(36756003)(33964004)(6506007)(2616005)(6512007)(2906002)(38100700002)(186003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wnT3Uj6LgwMZPmvzk8HYLAYIiiwG?= =?utf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utf-8?q?xj4x/qQ4yZhDsVlnpdW+vGT0SVVMXM2Xw/4C2qQiznPm12x64HLK0Yocs1j89UQmc?= =?utf-8?q?MlIgSRFm+eVabEpIqqvp+cVc1s7+UPKqdUxQ9n/oWeyR9Jb1NTqzPAa4xX7/YyF0N?= =?utf-8?q?2WB6T83Rr/P7FOl2ZAk6MxxuaAgBcYgN5ABOHvQ6G8breVlOC+iKTxGx7RE57bt4K?= =?utf-8?q?RIfAleMFkl7LDVF1PRFwaoEIK1t4JRUAGIDg+PV671sHmxpXdPA6qsaOrXURlO94X?= =?utf-8?q?jJRnF7RcsMoLm0/NhH/gXU/biYOD5u5FYh8T5ar9lZYEISFA2LP9FlkeCAgW9n5kI?= =?utf-8?q?F6rx4gAt7Kh57p78Yc+kzE0iWrUX/OG8S8/P8Zi0+fj8fwJn9xx3EUlBm7YSMzgig?= =?utf-8?q?q2lkprrcBrXVVjr/QPGHvUADpNI/xLmYmbhuDqqazen2fAQoCJWGk9fJHO18YPsQ3?= =?utf-8?q?bln8aDl7hHi7EbdQyXSVZt8JX8SUO2I2D8VGidcrfOJ6kDNCDqcjEGYBc2VdrA7Og?= =?utf-8?q?T7oeEEUNuCVMC98ig4EYs0Ei/gKnLNJs+syEV4ul3cjiN4jDFXIoqiqag5QdspgoU?= =?utf-8?q?D3q21rNePBgZiMIdCLVYdZgeQ2KyQJOkQj7pt2VaiviLh55ZMCuIX2Au+Sw/zYVVl?= =?utf-8?q?01URGjtkgKpLE8JrEtuzv2fF1kihBGOwhpYkhuGKRkkWaMebVBGp0BM=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0aab5493-443b-4bcf-1694-08da89bfc8de X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB7104.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2022 13:10:02.9977 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LQpDVLOjspho7xB6N2p96/B7E5czWIRAI0nGP3Qsq5IgOBxED+zZeXks1x+SwSHvOFZ90FcCC2VY+wpx8DqTVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0401MB2583 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi, I am looking at that patch and I am afraid, while it does the job it is quite unclean. In effect you introduce a flag you set, but never clear. That is just a kludge. It really tells you that your setup of data structures is misplaced and you should just do it earlier. Could you test the attached patch? Regards Oliver From a11e0684f338f6cf003eb5dfb562d91da1866cc8 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Mon, 29 Aug 2022 14:42:17 +0200 Subject: [PATCH] initialize struct otg_fsm earlier The earlier fix bf88fef0b6f1 ("usb: otg-fsm: Fix hrtimer list corruption") in effect hid an issue with intialization. In effect it replaces the racy continous reinitialization of fsm->hnp_polling_work with a delayed one-time initialization. This just makes no sense. As a single initialization is sufficient, the clean solution is just to do it once and do it early enough. Fixes: bf88fef0b6f1 ("usb: otg-fsm: Fix hrtimer list corruption") Signed-off-by: Oliver Neukum --- drivers/usb/common/usb-otg-fsm.c | 7 +------ drivers/usb/phy/phy-fsl-usb.c | 1 + include/linux/usb/otg-fsm.h | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/usb/common/usb-otg-fsm.c b/drivers/usb/common/usb-otg-fsm.c index 0697fde51d00..0aa2eb7396ce 100644 --- a/drivers/usb/common/usb-otg-fsm.c +++ b/drivers/usb/common/usb-otg-fsm.c @@ -117,7 +117,7 @@ static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) } } -static void otg_hnp_polling_work(struct work_struct *work) +void otg_hnp_polling_work(struct work_struct *work) { struct otg_fsm *fsm = container_of(to_delayed_work(work), struct otg_fsm, hnp_polling_work); @@ -193,11 +193,6 @@ static void otg_start_hnp_polling(struct otg_fsm *fsm) if (!fsm->host_req_flag) return; - if (!fsm->hnp_work_inited) { - INIT_DELAYED_WORK(&fsm->hnp_polling_work, otg_hnp_polling_work); - fsm->hnp_work_inited = true; - } - schedule_delayed_work(&fsm->hnp_polling_work, msecs_to_jiffies(T_HOST_REQ_POLL)); } diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index 972704262b02..c3bac7eefe82 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c @@ -844,6 +844,7 @@ int usb_otg_start(struct platform_device *pdev) /* Initialize the state machine structure with default values */ SET_OTG_STATE(otg_trans, OTG_STATE_UNDEFINED); + INIT_DELAYED_WORK(&fsm->hnp_polling_work, otg_hnp_polling_work); fsm->otg = p_otg->phy.otg; /* We don't require predefined MEM/IRQ resource index */ diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h index 6135d076c53d..cc0bc4edf227 100644 --- a/include/linux/usb/otg-fsm.h +++ b/include/linux/usb/otg-fsm.h @@ -183,7 +183,6 @@ struct otg_fsm { struct mutex lock; u8 *host_req_flag; struct delayed_work hnp_polling_work; - bool hnp_work_inited; bool state_changed; }; -- 2.35.3