From patchwork Fri Dec 13 12:03:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 3339831 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 65E4EC0D4A for ; Fri, 13 Dec 2013 12:01:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4994F207C5 for ; Fri, 13 Dec 2013 12:01:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 14890207BF for ; Fri, 13 Dec 2013 12:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752293Ab3LMMBX (ORCPT ); Fri, 13 Dec 2013 07:01:23 -0500 Received: from mga02.intel.com ([134.134.136.20]:44536 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751496Ab3LMMBW (ORCPT ); Fri, 13 Dec 2013 07:01:22 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 13 Dec 2013 04:01:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,478,1384329600"; d="scan'208";a="451783513" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga002.jf.intel.com with ESMTP; 13 Dec 2013 04:01:19 -0800 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id ED7FA202A2 for ; Fri, 13 Dec 2013 14:01:18 +0200 (EET) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id DA2A8200A6; Fri, 13 Dec 2013 14:03:36 +0200 (EET) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [RFC 2/2] media: v4l: Only get module if it's different than the driver for v4l2_dev Date: Fri, 13 Dec 2013 14:03:36 +0200 Message-Id: <1386936216-32296-2-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386936216-32296-1-git-send-email-sakari.ailus@linux.intel.com> References: <1386936216-32296-1-git-send-email-sakari.ailus@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the sub-device is registered, increment the use count of the sub-device owner only if it's different from the owner of the driver for the media device. This avoids increasing the use count by the module itself and thus making it possible to unload it when it's not in use. Signed-off-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c index 02d1b63..9f6d1ec 100644 --- a/drivers/media/v4l2-core/v4l2-device.c +++ b/drivers/media/v4l2-core/v4l2-device.c @@ -158,7 +158,8 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, /* Warn if we apparently re-register a subdev */ WARN_ON(sd->v4l2_dev != NULL); - if (!try_module_get(sd->owner)) + if (sd->owner != v4l2_dev->dev->driver->owner && + !try_module_get(sd->owner)) return -ENODEV; sd->v4l2_dev = v4l2_dev; @@ -192,7 +193,8 @@ error_unregister: if (sd->internal_ops && sd->internal_ops->unregistered) sd->internal_ops->unregistered(sd); error_module: - module_put(sd->owner); + if (sd->owner != v4l2_dev->dev->driver->owner) + module_put(sd->owner); sd->v4l2_dev = NULL; return err; } @@ -280,6 +282,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) } #endif video_unregister_device(sd->devnode); - module_put(sd->owner); + if (sd->owner != v4l2_dev->dev->driver->owner) + module_put(sd->owner); } EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);