From patchwork Mon Jul 17 16:59:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9845807 X-Patchwork-Delegate: geert@linux-m68k.org 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 B540960393 for ; Mon, 17 Jul 2017 17:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A633E28554 for ; Mon, 17 Jul 2017 17:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B15E2857B; Mon, 17 Jul 2017 17:00:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 55E222857D for ; Mon, 17 Jul 2017 17:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751313AbdGQRA1 (ORCPT ); Mon, 17 Jul 2017 13:00:27 -0400 Received: from smtp-4.sys.kth.se ([130.237.48.193]:35440 "EHLO smtp-4.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751314AbdGQRAZ (ORCPT ); Mon, 17 Jul 2017 13:00:25 -0400 Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id 9EE113211; Mon, 17 Jul 2017 19:00:23 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8c0NpwQgMUX8; Mon, 17 Jul 2017 19:00:23 +0200 (CEST) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id A8AE43148; Mon, 17 Jul 2017 19:00:22 +0200 (CEST) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , Laurent Pinchart , linux-media@vger.kernel.org Cc: Kieran Bingham , linux-renesas-soc@vger.kernel.org, Maxime Ripard , Sylwester Nawrocki , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v4 2/3] v4l: async: do not hold list_lock when reprobing devices Date: Mon, 17 Jul 2017 18:59:16 +0200 Message-Id: <20170717165917.24851-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170717165917.24851-1-niklas.soderlund+renesas@ragnatech.se> References: <20170717165917.24851-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no good reason to hold the list_lock when reprobing the devices and it prevents a clean implementation of subdevice notifiers. Move the actual release of the devices outside of the loop which requires the lock to be held. Signed-off-by: Niklas Söderlund --- drivers/media/v4l2-core/v4l2-async.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 0acf288d7227ba97..8fc84f7962386ddd 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -206,7 +206,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) unsigned int notif_n_subdev = notifier->num_subdevs; unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS); struct device **dev; - int i = 0; + int i, count = 0; if (!notifier->v4l2_dev) return; @@ -222,37 +222,28 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) list_del(¬ifier->list); list_for_each_entry_safe(sd, tmp, ¬ifier->done, async_list) { - struct device *d; - - d = get_device(sd->dev); + if (dev) + dev[count] = get_device(sd->dev); + count++; if (notifier->unbind) notifier->unbind(notifier, sd, sd->asd); v4l2_async_cleanup(sd); + } - /* If we handled USB devices, we'd have to lock the parent too */ - device_release_driver(d); + mutex_unlock(&list_lock); - /* - * Store device at the device cache, in order to call - * put_device() on the final step - */ + for (i = 0; i < count; i++) { + /* If we handled USB devices, we'd have to lock the parent too */ if (dev) - dev[i++] = d; - else - put_device(d); + device_release_driver(dev[i]); } - mutex_unlock(&list_lock); - /* * Call device_attach() to reprobe devices - * - * NOTE: If dev allocation fails, i is 0, and the whole loop won't be - * executed. */ - while (i--) { + for (i = 0; dev && i < count; i++) { struct device *d = dev[i]; if (d && device_attach(d) < 0) {