Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3973103pxj; Tue, 8 Jun 2021 03:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNVspbaknYwmLShih164fBiXErhsb/HWdd+TqVnAHKJBOt3cNkb7ZNfyMnbsknE/h2nWLW X-Received: by 2002:a17:906:c00f:: with SMTP id e15mr23844295ejz.458.1623148080176; Tue, 08 Jun 2021 03:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623148080; cv=none; d=google.com; s=arc-20160816; b=CV3XBUZe50ZD9uuIdvhRzo5GdSk5y8AujFpsqjrz988HPIC8PEwgo4b0Ujb45dZ4/o AdUJY/K3fMGgAtAqdBXG5GRHm0spHQh5bVMaTwGKsYaefyzsjICT9iNdOY/iRYjfEQ0g MezZBCr+815DHW9I/He2pvEVlMWcL+wAObNLVrRbYIpZHBD03BpmVV3D+ueAVMmgUe3Q I98cCd25oppu0NVZRnPL3EZ+Rzu7O0o56dwUWSP9HkN7gQ4NbOGRzBo3dSUVz/4g6MpV /6QVh+bCvu87lrU7M4X38pj3O2Z56wR6Khj1/gjsiYGBFCGDF3VYjAMVJLM/fxt0XS4i uIuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=x0Bhz05IKdTNr57LviEu/A1ZvlgQ2LGE1gaNPef2MLY=; b=CxIo8LtrVx+yyt5j3lrk3o0yes1GoINZSfkBB7ufvgVrlIkERY/VPvKQoj09TCL6p7 P6y5WfxeiMSs93UMP43+dJT1Pq9SvaUrctGct/1376rRiD1GVUKAfDip6n8eXuBXWC+O lSrqB9XHD3gkyOfxczM/Sh2xcbRKqzWP5P8lkPjlbKZ7TW1TJ6Xby1JTfPa16D66hjPQ hHx7sAWCl/aRdG8/msU/adiAgWrqUDTN/FEa9neo1knkZsM+2D2SYXDvyR99NJmDLkDz DfF6Xmo17DWuMwZSmRsjRccSP+RAL9Z5TsVEAErEugZbuqmpz4Yi9E/4XFYmmPgnD/ws S9Nw== 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 eb8si3149397edb.249.2021.06.08.03.27.35; Tue, 08 Jun 2021 03:28:00 -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 S231320AbhFHKLN (ORCPT + 99 others); Tue, 8 Jun 2021 06:11:13 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:39781 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbhFHKLM (ORCPT ); Tue, 8 Jun 2021 06:11:12 -0400 Received: by mail-lf1-f44.google.com with SMTP id p17so30422579lfc.6 for ; Tue, 08 Jun 2021 03:09:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=x0Bhz05IKdTNr57LviEu/A1ZvlgQ2LGE1gaNPef2MLY=; b=BkM8GgQhusUqfFBPFWR8m1p0zUd1sYuJHya6fVvV2O2F517SyQLSsdVU2OyQkr9t+S EFHs9rmBKOLuTKvpJr4Lm51cCiaoqBwTMUYwFU1y7jLFS0y1wv5YaUAaU2RlPi0wg+SI WH46vYB4GQC3S9/o+zoP/EwNqTrFS5aLMJ0isoSfyxl6lCprj/yTi6M1+qGBMEGJB9zN lQNZQgJDpZsuHsPSR3p8Jvmfn4t0uiGfNFU3gXTd/Ogc1u2Io9BPb6cBOnlRNtNi6cBg K2oTzHCba4xNBOpThYNGbxMdEhR0QP5gG01NjAmZgdMxL5agE78tmFZfgyYFwwOOiYPl ff+A== X-Gm-Message-State: AOAM532c1s4QTCxSVn9eDVn1TLRiEDq4c0uGATghuMmOknp03d8xKbZv D4m6NsbVE6rFgeaylTrQyzE= X-Received: by 2002:a19:8083:: with SMTP id b125mr14347496lfd.204.1623146959157; Tue, 08 Jun 2021 03:09:19 -0700 (PDT) Received: from dc7vkhyh15000m40t6jht-3.rev.dnainternet.fi (dc7vkhyyyyyyyyyyyyycy-3.rev.dnainternet.fi. [2001:14ba:16e2:8300::4]) by smtp.gmail.com with ESMTPSA id n17sm1566589lfh.220.2021.06.08.03.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 03:09:18 -0700 (PDT) Date: Tue, 8 Jun 2021 13:09:12 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Chanwoo Choi , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , MyungJoo Ham , Hans de Goede , Matti Vaittinen , Marek Szyprowski , linux-kernel@vger.kernel.org Subject: [PATCH RESEND v2 0/5] Add devm helper for work-queue initialization Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MGYHOYXEY6WxJCY8" Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This series adds new devm_work_autocancel() helper. Note: "The beef" of this series is the new devm-helper. This means that normally it would be picked-up by Hans. In this case Hans asked if this series could be taken in extconn tree: https://lore.kernel.org/lkml/fbbfba71-bdcc-b78f-48be-d7c657adce61@redhat.co= m/ Many drivers which use work-queues must ensure the work is not queued when driver is detached. Often this is done by ensuring new work is not added and then calling cancel_work_sync() at remove(). In many cases this also requir= es cleanup at probe error path - which is easy to forget (or get wrong). Also the "by ensuring new work is not added" has a gotcha. It is not strange to see devm managed IRQs scheduling work. Mixing this with manual wq clean-up is hard to do correctly because the devm is likely to free the IRQ only after the remove() is ran. So manual wq cancellation and devm-based IRQ management do not mix well - there is a short(?) time-window after the wq clean-up when IRQs are still not freed and may schedule new work. When both WQs and IRQs are managed by devm things are likely to just work. WQs should be initialized before IRQs (when IRQs need to schedule work) and devm unwinds things in "FILO" order. This series implements wq cancellation on top of devm and replaces the obvious cases where only thing remove call-back in a driver does is cancelling the work. There might be other cases where we could switch more than just work cancellation to use managed version and thus get rid of remove or mixed (manual and devm) resource management. Changelog v2: - rebased on v5.13-rc2 - split the extcon-max8997 change into two. First a simple, back-portable fix for omitting IRQ freeing at error path, second being the devm-simpification which does not need backporting. --- Matti Vaittinen (5): devm-helpers: Add resource managed version of work init extcon: extcon-max14577: Fix potential work-queue cancellation race extcon: extcon-max77693.c: Fix potential work-queue cancellation race extcon: extcon-max8997: Fix IRQ freeing at error path extcon: extcon-max8997: Simplify driver using devm drivers/extcon/extcon-max14577.c | 16 ++++-------- drivers/extcon/extcon-max77693.c | 17 ++++-------- drivers/extcon/extcon-max8997.c | 45 +++++++++++--------------------- include/linux/devm-helpers.h | 25 ++++++++++++++++++ 4 files changed, 50 insertions(+), 53 deletions(-) base-commit: d07f6ca923ea0927a1024dfccafc5b53b61cfecc --=20 2.25.4 --=20 Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please. ~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =3D]=20 --MGYHOYXEY6WxJCY8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmC/QbYACgkQeFA3/03a ocWVkAgAkgdmVUXw7/c2OcDYQnNDHZfPtRF3VqV3cPt8sd/ofPjq7WoWIJtVBF7d QDA+KtyxJVhJFw/+1D0AkqRedbVmluO64Nw20amqvSEQlBTRfno3RDkyspXDPYkK yyiD9b8g98GGVNmKRbfiZJzE9Gg3heO922R9kB36hBfrIbj6r6rTH+0glp3KDWwk uLj3DRHWgyRi7PUVOQjcYfQr9IC9jzTnPcNXuQc/iYyDQN/iI5TGcd1V5NVIXi1M CWvLdwDeHkfsjkHZXyOGiQvBNDlfYNCEJxhOF6qfPCLlmni1NkJ7KL5yG8iQcqhr xnePyvmy290qVxn+tSX2saef5PE20g== =wgrs -----END PGP SIGNATURE----- --MGYHOYXEY6WxJCY8--