From patchwork Wed Jul 19 10:49:44 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: 9851489 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 D91B560388 for ; Wed, 19 Jul 2017 10:50:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D82F2285EE for ; Wed, 19 Jul 2017 10:50:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD1382861F; Wed, 19 Jul 2017 10:50:26 +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=ham 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 80E472863E for ; Wed, 19 Jul 2017 10:50:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753651AbdGSKuW (ORCPT ); Wed, 19 Jul 2017 06:50:22 -0400 Received: from smtp-3.sys.kth.se ([130.237.48.192]:52666 "EHLO smtp-3.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365AbdGSKuS (ORCPT ); Wed, 19 Jul 2017 06:50:18 -0400 Received: from smtp-3.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-3.sys.kth.se (Postfix) with ESMTP id 18ED2286D; Wed, 19 Jul 2017 12:50:17 +0200 (CEST) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-3.sys.kth.se ([127.0.0.1]) by smtp-3.sys.kth.se (smtp-3.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id bABzj8Fnk1HI; Wed, 19 Jul 2017 12:50:16 +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-3.sys.kth.se (Postfix) with ESMTPSA id 1CA7B293F; Wed, 19 Jul 2017 12:50:16 +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 v5 2/4] v4l: async: abort if memory allocation fails when unregistering notifiers Date: Wed, 19 Jul 2017 12:49:44 +0200 Message-Id: <20170719104946.7322-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170719104946.7322-1-niklas.soderlund+renesas@ragnatech.se> References: <20170719104946.7322-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of trying to cope with the failed memory allocation and still leaving the kernel in a semi-broken state (the subdevices will be released but never re-probed) simply abort. The kernel have already printed a warning about allocation failure but keep the error printout to ease pinpointing the problem if it happens. By doing this we can increase the readability of this complex function which puts it in a better state to separate the v4l2 housekeeping tasks from the re-probing of devices. It also serves to prepare for adding subnotifers. Signed-off-by: Niklas Söderlund --- drivers/media/v4l2-core/v4l2-async.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 0acf288d7227ba97..67852f0f2d3000c9 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -215,6 +215,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) if (!dev) { dev_err(notifier->v4l2_dev->dev, "Failed to allocate device cache!\n"); + return; } mutex_lock(&list_lock); @@ -234,23 +235,13 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) /* If we handled USB devices, we'd have to lock the parent too */ device_release_driver(d); - /* - * Store device at the device cache, in order to call - * put_device() on the final step - */ - if (dev) - dev[i++] = d; - else - put_device(d); + dev[i++] = d; } 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--) { struct device *d = dev[i];