From patchwork Tue Mar 5 09:58:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA2871390 for ; Tue, 5 Mar 2019 09:58:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F9BC2847A for ; Tue, 5 Mar 2019 09:58:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EEA223201; Tue, 5 Mar 2019 09:58:56 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 E512A2AB3D for ; Tue, 5 Mar 2019 09:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbfCEJ6y (ORCPT ); Tue, 5 Mar 2019 04:58:54 -0500 Received: from lb2-smtp-cloud7.xs4all.net ([194.109.24.28]:40881 "EHLO lb2-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727367AbfCEJ6x (ORCPT ); Tue, 5 Mar 2019 04:58:53 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qZhrcse; Tue, 05 Mar 2019 10:58:52 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 1/9] cec: fill in cec chardev kobject to ease debugging Date: Tue, 5 Mar 2019 10:58:39 +0100 Message-Id: <20190305095847.21428-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfP+uY9uGQYe20y5TGuTJqaR1zB8TGzHZINr7yBiK0P7Q/AhAt1T1lYldFKqjWoC51MuN/RZdoEhi8FCg/8rXZV4ZU/kx55IbUacHm5wv8+GFEGt0O0jx nDSXLgWi5xm34zC5xkThlbZsuXcyG39PofBCS5yyhiMTEMUktaBe/oEwU7JJN6jV3dfEhuHsQi17yvr9okq7c8fv2P23dIkQns0gvrZS76YvNobC5f0nCCIh 1B9yKdJG1JxnFnvP1aTSVjV+ty2ih3ViE1YKg9+MBI2xGAbcnSSuh+QmvMZ0m/mvE6nrl7eWbLwPqBYREdVkfQ== 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 From: Hans Verkuil The cec chardev kobject has no name, which made it hard to debug when kobject debugging is turned on. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/cec/cec-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index cc875dabd765..f5d1578e256a 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -126,6 +126,7 @@ static int __must_check cec_devnode_register(struct cec_devnode *devnode, /* Part 2: Initialize and register the character device */ cdev_init(&devnode->cdev, &cec_devnode_fops); devnode->cdev.owner = owner; + kobject_set_name(&devnode->cdev.kobj, "cec%d", devnode->minor); ret = cdev_device_add(&devnode->cdev, &devnode->dev); if (ret) { From patchwork Tue Mar 5 09:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A59E1390 for ; Tue, 5 Mar 2019 09:58:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CD0D2AB0A for ; Tue, 5 Mar 2019 09:58:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 405972AB88; Tue, 5 Mar 2019 09:58:55 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 A57D92AB0A for ; Tue, 5 Mar 2019 09:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727513AbfCEJ6x (ORCPT ); Tue, 5 Mar 2019 04:58:53 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:46429 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbfCEJ6x (ORCPT ); Tue, 5 Mar 2019 04:58:53 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qahrcsp; Tue, 05 Mar 2019 10:58:52 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 2/9] media-devnode: fill in media chardev kobject to ease debugging Date: Tue, 5 Mar 2019 10:58:40 +0100 Message-Id: <20190305095847.21428-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfP+uY9uGQYe20y5TGuTJqaR1zB8TGzHZINr7yBiK0P7Q/AhAt1T1lYldFKqjWoC51MuN/RZdoEhi8FCg/8rXZV4ZU/kx55IbUacHm5wv8+GFEGt0O0jx nDSXLgWi5xm34zC5xkThlbZsuXcyG39PofBCS5yyhiMTEMUktaBe/oEwU7JJN6jV3dfEhuHsQi17yvr9okq7c8fv2P23dIkQns0gvrZS76YvNobC5f0nCCIh 1B9yKdJG1JxnFnvP1aTSVjV+ty2ih3ViE1YKg9+MBI2xGAbcnSSuh+QmvMZ0m/mvE6nrl7eWbLwPqBYREdVkfQ== 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 From: Hans Verkuil The media chardev kobject has no name, which made it hard to debug when kobject debugging is turned on. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/media-devnode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c index 6b87a721dc49..61dc05fcc55c 100644 --- a/drivers/media/media-devnode.c +++ b/drivers/media/media-devnode.c @@ -251,6 +251,7 @@ int __must_check media_devnode_register(struct media_device *mdev, /* Part 2: Initialize the character device */ cdev_init(&devnode->cdev, &media_devnode_fops); devnode->cdev.owner = owner; + kobject_set_name(&devnode->cdev.kobj, "media%d", devnode->minor); /* Part 3: Add the media and char device */ ret = cdev_device_add(&devnode->cdev, &devnode->dev); From patchwork Tue Mar 5 09:58:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01AA51669 for ; Tue, 5 Mar 2019 09:58:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4A162842D for ; Tue, 5 Mar 2019 09:58:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96D6327F94; Tue, 5 Mar 2019 09:58:56 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 318DF2AB0A for ; Tue, 5 Mar 2019 09:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727619AbfCEJ6z (ORCPT ); Tue, 5 Mar 2019 04:58:55 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:59281 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbfCEJ6y (ORCPT ); Tue, 5 Mar 2019 04:58:54 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qahrct0; Tue, 05 Mar 2019 10:58:52 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 3/9] vivid: use vzalloc for dev->bitmap_out Date: Tue, 5 Mar 2019 10:58:41 +0100 Message-Id: <20190305095847.21428-4-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfP+uY9uGQYe20y5TGuTJqaR1zB8TGzHZINr7yBiK0P7Q/AhAt1T1lYldFKqjWoC51MuN/RZdoEhi8FCg/8rXZV4ZU/kx55IbUacHm5wv8+GFEGt0O0jx nDSXLgWi5xm34zC5xkThlbZsuXcyG39PofBCS5yyhiMTEMUktaBe/oEwU7JJN6jV3dfEhuHsQi17yvr9okq7c8fv2P23dIkQns0gvrZS76YvNobC5f0nCCIh 1B9yKdJG1JxnFnvP1aTSVjV+ty2ih3ViE1YKg9+MBI2xGAbcnSSuh+QmvMZ0m/mvE6nrl7eWbLwPqBYREdVkfQ== 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 From: Hans Verkuil When vivid is unloaded it used vfree to free dev->bitmap_out, but it was actually allocated using kmalloc. Use vzalloc instead, conform what vivid-vid-cap.c does. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/platform/vivid/vivid-vid-out.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c index e61b91b414f9..9350ca65dd91 100644 --- a/drivers/media/platform/vivid/vivid-vid-out.c +++ b/drivers/media/platform/vivid/vivid-vid-out.c @@ -798,7 +798,7 @@ int vivid_vid_out_s_selection(struct file *file, void *fh, struct v4l2_selection s->r.height *= factor; if (dev->bitmap_out && (compose->width != s->r.width || compose->height != s->r.height)) { - kfree(dev->bitmap_out); + vfree(dev->bitmap_out); dev->bitmap_out = NULL; } *compose = s->r; @@ -941,15 +941,19 @@ int vidioc_s_fmt_vid_out_overlay(struct file *file, void *priv, return ret; if (win->bitmap) { - new_bitmap = memdup_user(win->bitmap, bitmap_size); + new_bitmap = vzalloc(bitmap_size); - if (IS_ERR(new_bitmap)) - return PTR_ERR(new_bitmap); + if (!new_bitmap) + return -ENOMEM; + if (copy_from_user(new_bitmap, win->bitmap, bitmap_size)) { + vfree(new_bitmap); + return -EFAULT; + } } dev->overlay_out_top = win->w.top; dev->overlay_out_left = win->w.left; - kfree(dev->bitmap_out); + vfree(dev->bitmap_out); dev->bitmap_out = new_bitmap; dev->clipcount_out = win->clipcount; if (dev->clipcount_out) From patchwork Tue Mar 5 09:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FF4B1390 for ; Tue, 5 Mar 2019 09:59:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CD732B439 for ; Tue, 5 Mar 2019 09:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A82D2B45C; Tue, 5 Mar 2019 09:59:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 C2B792B43B for ; Tue, 5 Mar 2019 09:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727615AbfCEJ6y (ORCPT ); Tue, 5 Mar 2019 04:58:54 -0500 Received: from lb2-smtp-cloud7.xs4all.net ([194.109.24.28]:38983 "EHLO lb2-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727497AbfCEJ6y (ORCPT ); Tue, 5 Mar 2019 04:58:54 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qahrctE; Tue, 05 Mar 2019 10:58:52 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 4/9] media-entity: set ent_enum->bmap to NULL after freeing it Date: Tue, 5 Mar 2019 10:58:42 +0100 Message-Id: <20190305095847.21428-5-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfP+uY9uGQYe20y5TGuTJqaR1zB8TGzHZINr7yBiK0P7Q/AhAt1T1lYldFKqjWoC51MuN/RZdoEhi8FCg/8rXZV4ZU/kx55IbUacHm5wv8+GFEGt0O0jx nDSXLgWi5xm34zC5xkThlbZsuXcyG39PofBCS5yyhiMTEMUktaBe/oEwU7JJN6jV3dfEhuHsQi17yvr9okq7c8fv2P23dIkQns0gvrZS76YvNobC5f0nCCIh 1B9yKdJG1JxnFnvP1aTSVjV+ty2ih3ViE1YKg9+MBI2xGAbcnSSuh+QmvMZ0m/mvE6nrl7eWbLwPqBYREdVkfQ== 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 From: Hans Verkuil Ensure that this pointer is set to NULL after it is freed. The vimc driver has a static media_entity and after unbinding and rebinding the vimc device the media code will try to free this pointer again since it wasn't set to NULL. Signed-off-by: Hans Verkuil --- drivers/media/media-entity.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 0b1cb3559140..7b2a2cc95530 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -88,6 +88,7 @@ EXPORT_SYMBOL_GPL(__media_entity_enum_init); void media_entity_enum_cleanup(struct media_entity_enum *ent_enum) { kfree(ent_enum->bmap); + ent_enum->bmap = NULL; } EXPORT_SYMBOL_GPL(media_entity_enum_cleanup); From patchwork Tue Mar 5 09:58:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AB9A1390 for ; Tue, 5 Mar 2019 09:58:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63A4729414 for ; Tue, 5 Mar 2019 09:58:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5702E2B2D8; Tue, 5 Mar 2019 09:58:58 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DCD45284B9 for ; Tue, 5 Mar 2019 09:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbfCEJ64 (ORCPT ); Tue, 5 Mar 2019 04:58:56 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:60058 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727498AbfCEJ6z (ORCPT ); Tue, 5 Mar 2019 04:58:55 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qahrctZ; Tue, 05 Mar 2019 10:58:53 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 5/9] vim2m: replace devm_kzalloc by kzalloc Date: Tue, 5 Mar 2019 10:58:43 +0100 Message-Id: <20190305095847.21428-6-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfOgZY9pHGq3jUv18ey9Nq2SqEEKLwqmmK3derkwav4eWjAt6zOaumShOc11pK5piiRj3JhquRmsiWcxoh1tPrTvpmX5CFaVHbmU09GkJ5qKzrA4829P2 dMkWOyG6ZtjLH+593MOVx9x8QhzrDA7IgoCcVDxBwN1ZlYWMXoXvq/qMSNMevR0fSXV4OA2D+f2JHN9UkQKQGVfdcnpSejeIkPXCnQpXgzeSUUrwMbcFhWdv YcgdUbxLzH2c7lJl4j2BOvvrx5KyAc5mIwd7SbWXqt47+xkduKf9asv9l6N6mPdbGxpFVWadyDCXH0sMbb6iaQ== 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 From: Hans Verkuil It is not possible to use devm_kzalloc since that memory is freed immediately when the device instance is unbound. Various objects like the video device may still be in use since someone has the device node open, and when that is closed it expects the memory to be around. So use kzalloc and release it at the appropriate time. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/platform/vim2m.c | 35 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 34dcaca45d8b..dd47821fc661 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -1262,6 +1262,15 @@ static int vim2m_release(struct file *file) return 0; } +static void vim2m_device_release(struct video_device *vdev) +{ + struct vim2m_dev *dev = container_of(vdev, struct vim2m_dev, vfd); + + v4l2_device_unregister(&dev->v4l2_dev); + v4l2_m2m_release(dev->m2m_dev); + kfree(dev); +} + static const struct v4l2_file_operations vim2m_fops = { .owner = THIS_MODULE, .open = vim2m_open, @@ -1277,7 +1286,7 @@ static const struct video_device vim2m_videodev = { .fops = &vim2m_fops, .ioctl_ops = &vim2m_ioctl_ops, .minor = -1, - .release = video_device_release_empty, + .release = vim2m_device_release, .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING, }; @@ -1298,13 +1307,13 @@ static int vim2m_probe(struct platform_device *pdev) struct video_device *vfd; int ret; - dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); if (ret) - return ret; + goto error_free; atomic_set(&dev->num_inst, 0); mutex_init(&dev->dev_mutex); @@ -1317,7 +1326,7 @@ static int vim2m_probe(struct platform_device *pdev) ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); - goto unreg_v4l2; + goto error_v4l2; } video_set_drvdata(vfd, dev); @@ -1330,7 +1339,7 @@ static int vim2m_probe(struct platform_device *pdev) if (IS_ERR(dev->m2m_dev)) { v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); ret = PTR_ERR(dev->m2m_dev); - goto unreg_dev; + goto error_dev; } #ifdef CONFIG_MEDIA_CONTROLLER @@ -1346,27 +1355,29 @@ static int vim2m_probe(struct platform_device *pdev) MEDIA_ENT_F_PROC_VIDEO_SCALER); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem media controller\n"); - goto unreg_m2m; + goto error_m2m; } ret = media_device_register(&dev->mdev); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register mem2mem media device\n"); - goto unreg_m2m_mc; + goto error_m2m_mc; } #endif return 0; #ifdef CONFIG_MEDIA_CONTROLLER -unreg_m2m_mc: +error_m2m_mc: v4l2_m2m_unregister_media_controller(dev->m2m_dev); -unreg_m2m: +error_m2m: v4l2_m2m_release(dev->m2m_dev); #endif -unreg_dev: +error_dev: video_unregister_device(&dev->vfd); -unreg_v4l2: +error_v4l2: v4l2_device_unregister(&dev->v4l2_dev); +error_free: + kfree(dev); return ret; } @@ -1382,9 +1393,7 @@ static int vim2m_remove(struct platform_device *pdev) v4l2_m2m_unregister_media_controller(dev->m2m_dev); media_device_cleanup(&dev->mdev); #endif - v4l2_m2m_release(dev->m2m_dev); video_unregister_device(&dev->vfd); - v4l2_device_unregister(&dev->v4l2_dev); return 0; } From patchwork Tue Mar 5 09:58:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD4821515 for ; Tue, 5 Mar 2019 09:59:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5CBC2B40B for ; Tue, 5 Mar 2019 09:59:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A5402B3FC; Tue, 5 Mar 2019 09:59:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 40C922B3D1 for ; Tue, 5 Mar 2019 09:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727624AbfCEJ67 (ORCPT ); Tue, 5 Mar 2019 04:58:59 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:39146 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbfCEJ6z (ORCPT ); Tue, 5 Mar 2019 04:58:55 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qbhrctj; Tue, 05 Mar 2019 10:58:53 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 6/9] v4l2-subdev: add release() internal op Date: Tue, 5 Mar 2019 10:58:44 +0100 Message-Id: <20190305095847.21428-7-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfOgZY9pHGq3jUv18ey9Nq2SqEEKLwqmmK3derkwav4eWjAt6zOaumShOc11pK5piiRj3JhquRmsiWcxoh1tPrTvpmX5CFaVHbmU09GkJ5qKzrA4829P2 dMkWOyG6ZtjLH+593MOVx9x8QhzrDA7IgoCcVDxBwN1ZlYWMXoXvq/qMSNMevR0fSXV4OA2D+f2JHN9UkQKQGVfdcnpSejeIkPXCnQpXgzeSUUrwMbcFhWdv YcgdUbxLzH2c7lJl4j2BOvvrx5KyAc5mIwd7SbWXqt47+xkduKf9asv9l6N6mPdbGxpFVWadyDCXH0sMbb6iaQ== 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 From: Hans Verkuil If the subdevice created a device node, then the v4l2_subdev cannot be freed until the last user of the device node closes it. This means that we need a release() callback in v4l2_subdev_internal_ops that is called from the video_device release function so the subdevice driver can postpone freeing memory until the that callback is called. If no video device node was created then the release callback can be called immediately when the subdev is unregistered. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-device.c | 19 ++++++++++++++----- include/media/v4l2-subdev.h | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c index e0ddb9a52bd1..7cca0de1b730 100644 --- a/drivers/media/v4l2-core/v4l2-device.c +++ b/drivers/media/v4l2-core/v4l2-device.c @@ -216,10 +216,18 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, } EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); +static void v4l2_subdev_release(struct v4l2_subdev *sd) +{ + struct module *owner = !sd->owner_v4l2_dev ? sd->owner : NULL; + + if (sd->internal_ops && sd->internal_ops->release) + sd->internal_ops->release(sd); + module_put(owner); +} + static void v4l2_device_release_subdev_node(struct video_device *vdev) { - struct v4l2_subdev *sd = video_get_drvdata(vdev); - sd->devnode = NULL; + v4l2_subdev_release(video_get_drvdata(vdev)); kfree(vdev); } @@ -318,8 +326,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) media_device_unregister_entity(&sd->entity); } #endif - video_unregister_device(sd->devnode); - if (!sd->owner_v4l2_dev) - module_put(sd->owner); + if (sd->devnode) + video_unregister_device(sd->devnode); + else + v4l2_subdev_release(sd); } EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 349e1c18cf48..2f2d1c8947e6 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -757,6 +757,8 @@ struct v4l2_subdev_ops { * * @close: called when the subdev device node is closed. * + * @release: called when the subdev device node is released. + * * .. note:: * Never call this from drivers, only the v4l2 framework can call * these ops. @@ -766,6 +768,7 @@ struct v4l2_subdev_internal_ops { void (*unregistered)(struct v4l2_subdev *sd); int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); + void (*release)(struct v4l2_subdev *sd); }; #define V4L2_SUBDEV_NAME_SIZE 32 From patchwork Tue Mar 5 09:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E1371390 for ; Tue, 5 Mar 2019 09:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 377002B2D8 for ; Tue, 5 Mar 2019 09:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BC932B3A8; Tue, 5 Mar 2019 09:58:59 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8541C2B2D8 for ; Tue, 5 Mar 2019 09:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727622AbfCEJ65 (ORCPT ); Tue, 5 Mar 2019 04:58:57 -0500 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:57970 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727367AbfCEJ64 (ORCPT ); Tue, 5 Mar 2019 04:58:56 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qbhrcts; Tue, 05 Mar 2019 10:58:53 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 7/9] v4l2-subdev: handle module refcounting here Date: Tue, 5 Mar 2019 10:58:45 +0100 Message-Id: <20190305095847.21428-8-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfOgZY9pHGq3jUv18ey9Nq2SqEEKLwqmmK3derkwav4eWjAt6zOaumShOc11pK5piiRj3JhquRmsiWcxoh1tPrTvpmX5CFaVHbmU09GkJ5qKzrA4829P2 dMkWOyG6ZtjLH+593MOVx9x8QhzrDA7IgoCcVDxBwN1ZlYWMXoXvq/qMSNMevR0fSXV4OA2D+f2JHN9UkQKQGVfdcnpSejeIkPXCnQpXgzeSUUrwMbcFhWdv YcgdUbxLzH2c7lJl4j2BOvvrx5KyAc5mIwd7SbWXqt47+xkduKf9asv9l6N6mPdbGxpFVWadyDCXH0sMbb6iaQ== 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 From: Hans Verkuil The module ownership refcounting was done in media_entity_get/put, but that was very confusing and it did not work either in case an application had a v4l-subdevX device open and the module was unbound. When the v4l-subdevX device was closed the media_entity_put was never called and the module refcount was left one too high, making it impossible to unload it. Since v4l2-subdev.c was the only place where media_entity_get/put was called, just move the functionality to v4l2-subdev.c and drop those confusing entity functions. Store the module in subdev_fh so module_put no longer depends on the media_entity struct. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/media-entity.c | 28 --------------------------- drivers/media/v4l2-core/v4l2-subdev.c | 22 +++++++++------------ include/media/media-entity.h | 24 ----------------------- include/media/v4l2-subdev.h | 1 + 4 files changed, 10 insertions(+), 65 deletions(-) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 7b2a2cc95530..257f20d2fb8a 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -17,7 +17,6 @@ */ #include -#include #include #include #include @@ -588,33 +587,6 @@ void media_pipeline_stop(struct media_entity *entity) } EXPORT_SYMBOL_GPL(media_pipeline_stop); -/* ----------------------------------------------------------------------------- - * Module use count - */ - -struct media_entity *media_entity_get(struct media_entity *entity) -{ - if (entity == NULL) - return NULL; - - if (entity->graph_obj.mdev->dev && - !try_module_get(entity->graph_obj.mdev->dev->driver->owner)) - return NULL; - - return entity; -} -EXPORT_SYMBOL_GPL(media_entity_get); - -void media_entity_put(struct media_entity *entity) -{ - if (entity == NULL) - return; - - if (entity->graph_obj.mdev->dev) - module_put(entity->graph_obj.mdev->dev->driver->owner); -} -EXPORT_SYMBOL_GPL(media_entity_put); - /* ----------------------------------------------------------------------------- * Links management */ diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index f5f0d71ec745..d75815ab0d7b 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -54,9 +55,6 @@ static int subdev_open(struct file *file) struct video_device *vdev = video_devdata(file); struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); struct v4l2_subdev_fh *subdev_fh; -#if defined(CONFIG_MEDIA_CONTROLLER) - struct media_entity *entity = NULL; -#endif int ret; subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL); @@ -73,12 +71,15 @@ static int subdev_open(struct file *file) v4l2_fh_add(&subdev_fh->vfh); file->private_data = &subdev_fh->vfh; #if defined(CONFIG_MEDIA_CONTROLLER) - if (sd->v4l2_dev->mdev) { - entity = media_entity_get(&sd->entity); - if (!entity) { + if (sd->v4l2_dev->mdev && sd->entity.graph_obj.mdev->dev) { + struct module *owner; + + owner = sd->entity.graph_obj.mdev->dev->driver->owner; + if (!try_module_get(owner)) { ret = -EBUSY; goto err; } + subdev_fh->owner = owner; } #endif @@ -91,9 +92,7 @@ static int subdev_open(struct file *file) return 0; err: -#if defined(CONFIG_MEDIA_CONTROLLER) - media_entity_put(entity); -#endif + module_put(subdev_fh->owner); v4l2_fh_del(&subdev_fh->vfh); v4l2_fh_exit(&subdev_fh->vfh); subdev_fh_free(subdev_fh); @@ -111,10 +110,7 @@ static int subdev_close(struct file *file) if (sd->internal_ops && sd->internal_ops->close) sd->internal_ops->close(sd, subdev_fh); -#if defined(CONFIG_MEDIA_CONTROLLER) - if (sd->v4l2_dev->mdev) - media_entity_put(&sd->entity); -#endif + module_put(subdev_fh->owner); v4l2_fh_del(vfh); v4l2_fh_exit(vfh); subdev_fh_free(subdev_fh); diff --git a/include/media/media-entity.h b/include/media/media-entity.h index e5f6960d92f6..3cbad42e3693 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -864,19 +864,6 @@ struct media_link *media_entity_find_link(struct media_pad *source, */ struct media_pad *media_entity_remote_pad(const struct media_pad *pad); -/** - * media_entity_get - Get a reference to the parent module - * - * @entity: The entity - * - * Get a reference to the parent media device module. - * - * The function will return immediately if @entity is %NULL. - * - * Return: returns a pointer to the entity on success or %NULL on failure. - */ -struct media_entity *media_entity_get(struct media_entity *entity); - /** * media_entity_get_fwnode_pad - Get pad number from fwnode * @@ -916,17 +903,6 @@ __must_check int media_graph_walk_init( */ void media_graph_walk_cleanup(struct media_graph *graph); -/** - * media_entity_put - Release the reference to the parent module - * - * @entity: The entity - * - * Release the reference count acquired by media_entity_get(). - * - * The function will return immediately if @entity is %NULL. - */ -void media_entity_put(struct media_entity *entity); - /** * media_graph_walk_start - Start walking the media graph at a * given entity diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 2f2d1c8947e6..33ba56f3dc1f 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -905,6 +905,7 @@ struct v4l2_subdev { */ struct v4l2_subdev_fh { struct v4l2_fh vfh; + struct module *owner; #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) struct v4l2_subdev_pad_config *pad; #endif From patchwork Tue Mar 5 09:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 971FE1869 for ; Tue, 5 Mar 2019 09:58:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 799992A52C for ; Tue, 5 Mar 2019 09:58:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D2CE29382; Tue, 5 Mar 2019 09:58:57 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 026BD285A0 for ; Tue, 5 Mar 2019 09:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727509AbfCEJ64 (ORCPT ); Tue, 5 Mar 2019 04:58:56 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:45308 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727612AbfCEJ6z (ORCPT ); Tue, 5 Mar 2019 04:58:55 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qbhrcu5; Tue, 05 Mar 2019 10:58:54 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 8/9] vimc: free vimc_cap_device when the last user disappears Date: Tue, 5 Mar 2019 10:58:46 +0100 Message-Id: <20190305095847.21428-9-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfKVX3gACdRf/H/ST8JLEPelAcdC+P/a1kXaZDRh709ooSttdKupVjUrGW83aPMrUmJDq1us7oos0lQ0USg7BmP/PiDZBLoNxazat71NQP7BWRX+z/o8V jZyU3McWMybCSayz7l7c1P1YuMPFMBBLRo+/g5qWsMRPB39GwgS7LIF19Ox4dRtFTh/+JLlxSL6Q0iSbiObZpnkIk/r8g8PHQx9MCqgWjj/Hd83dLSQOiQDR hQiKotbBRK9bn3s28QGwydIu++sp2Yi+Yg0TVR4XDmReYupa1Vl2wyE8Ew+6gdGtL+soiu9KFzXmAWZINr7w3A== 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 From: Hans Verkuil Don't free vimc_cap_device immediately, instead do this in the video_device release function which is called when the last user closes the video device. Only then is it safe to free the memory. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/platform/vimc/vimc-capture.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index ea869631a3f6..3d433361d297 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -338,6 +338,15 @@ static const struct media_entity_operations vimc_cap_mops = { .link_validate = vimc_link_validate, }; +static void vimc_cap_release(struct video_device *vdev) +{ + struct vimc_cap_device *vcap = container_of(vdev, struct vimc_cap_device, + vdev); + + vimc_pads_cleanup(vcap->ved.pads); + kfree(vcap); +} + static void vimc_cap_comp_unbind(struct device *comp, struct device *master, void *master_data) { @@ -348,8 +357,6 @@ static void vimc_cap_comp_unbind(struct device *comp, struct device *master, vb2_queue_release(&vcap->queue); media_entity_cleanup(ved->ent); video_unregister_device(&vcap->vdev); - vimc_pads_cleanup(vcap->ved.pads); - kfree(vcap); } static void *vimc_cap_process_frame(struct vimc_ent_device *ved, @@ -467,7 +474,7 @@ static int vimc_cap_comp_bind(struct device *comp, struct device *master, vdev = &vcap->vdev; vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; vdev->entity.ops = &vimc_cap_mops; - vdev->release = video_device_release_empty; + vdev->release = vimc_cap_release; vdev->fops = &vimc_cap_fops; vdev->ioctl_ops = &vimc_cap_ioctl_ops; vdev->lock = &vcap->lock; From patchwork Tue Mar 5 09:58:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10839185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C54581869 for ; Tue, 5 Mar 2019 09:59:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10F02B40B for ; Tue, 5 Mar 2019 09:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E6B2B41D; Tue, 5 Mar 2019 09:59:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 CAE2E2B40B for ; Tue, 5 Mar 2019 09:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727623AbfCEJ67 (ORCPT ); Tue, 5 Mar 2019 04:58:59 -0500 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:56433 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727546AbfCEJ64 (ORCPT ); Tue, 5 Mar 2019 04:58:56 -0500 Received: from test-no.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id 16qVhtdVBLMwI16qchrcuQ; Tue, 05 Mar 2019 10:58:54 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Helen Koike , Hans Verkuil Subject: [PATCHv2 9/9] vimc: use new release op Date: Tue, 5 Mar 2019 10:58:47 +0100 Message-Id: <20190305095847.21428-10-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> References: <20190305095847.21428-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfKVX3gACdRf/H/ST8JLEPelAcdC+P/a1kXaZDRh709ooSttdKupVjUrGW83aPMrUmJDq1us7oos0lQ0USg7BmP/PiDZBLoNxazat71NQP7BWRX+z/o8V jZyU3McWMybCSayz7l7c1P1YuMPFMBBLRo+/g5qWsMRPB39GwgS7LIF19Ox4dRtFTh/+JLlxSL6Q0iSbiObZpnkIk/r8g8PHQx9MCqgWjj/Hd83dLSQOiQDR hQiKotbBRK9bn3s28QGwydIu++sp2Yi+Yg0TVR4XDmReYupa1Vl2wyE8Ew+6gdGtL+soiu9KFzXmAWZINr7w3A== 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 From: Hans Verkuil Use the new v4l2_subdev_internal_ops release op to free the subdev memory only once the last user closed the file handle. Signed-off-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- drivers/media/platform/vimc/vimc-common.c | 2 ++ drivers/media/platform/vimc/vimc-common.h | 2 ++ drivers/media/platform/vimc/vimc-debayer.c | 15 +++++++++++++-- drivers/media/platform/vimc/vimc-scaler.c | 15 +++++++++++++-- drivers/media/platform/vimc/vimc-sensor.c | 19 +++++++++++++++---- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-common.c b/drivers/media/platform/vimc/vimc-common.c index c1a74bb2df58..0adbfd8fd26d 100644 --- a/drivers/media/platform/vimc/vimc-common.c +++ b/drivers/media/platform/vimc/vimc-common.c @@ -380,6 +380,7 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved, u32 function, u16 num_pads, const unsigned long *pads_flag, + const struct v4l2_subdev_internal_ops *sd_int_ops, const struct v4l2_subdev_ops *sd_ops) { int ret; @@ -394,6 +395,7 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved, /* Initialize the subdev */ v4l2_subdev_init(sd, sd_ops); + sd->internal_ops = sd_int_ops; sd->entity.function = function; sd->entity.ops = &vimc_ent_sd_mops; sd->owner = THIS_MODULE; diff --git a/drivers/media/platform/vimc/vimc-common.h b/drivers/media/platform/vimc/vimc-common.h index 84539430b5e7..07987eab988f 100644 --- a/drivers/media/platform/vimc/vimc-common.h +++ b/drivers/media/platform/vimc/vimc-common.h @@ -187,6 +187,7 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat); * @function: media entity function defined by MEDIA_ENT_F_* macros * @num_pads: number of pads to initialize * @pads_flag: flags to use in each pad + * @sd_int_ops: pointer to &struct v4l2_subdev_internal_ops. * @sd_ops: pointer to &struct v4l2_subdev_ops. * * Helper function initialize and register the struct vimc_ent_device and struct @@ -199,6 +200,7 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved, u32 function, u16 num_pads, const unsigned long *pads_flag, + const struct v4l2_subdev_internal_ops *sd_int_ops, const struct v4l2_subdev_ops *sd_ops); /** diff --git a/drivers/media/platform/vimc/vimc-debayer.c b/drivers/media/platform/vimc/vimc-debayer.c index 7d77c63b99d2..eaed4233ad1b 100644 --- a/drivers/media/platform/vimc/vimc-debayer.c +++ b/drivers/media/platform/vimc/vimc-debayer.c @@ -489,6 +489,18 @@ static void *vimc_deb_process_frame(struct vimc_ent_device *ved, } +static void vimc_deb_release(struct v4l2_subdev *sd) +{ + struct vimc_deb_device *vdeb = + container_of(sd, struct vimc_deb_device, sd); + + kfree(vdeb); +} + +static const struct v4l2_subdev_internal_ops vimc_deb_int_ops = { + .release = vimc_deb_release, +}; + static void vimc_deb_comp_unbind(struct device *comp, struct device *master, void *master_data) { @@ -497,7 +509,6 @@ static void vimc_deb_comp_unbind(struct device *comp, struct device *master, ved); vimc_ent_sd_unregister(ved, &vdeb->sd); - kfree(vdeb); } static int vimc_deb_comp_bind(struct device *comp, struct device *master, @@ -519,7 +530,7 @@ static int vimc_deb_comp_bind(struct device *comp, struct device *master, MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV, 2, (const unsigned long[2]) {MEDIA_PAD_FL_SINK, MEDIA_PAD_FL_SOURCE}, - &vimc_deb_ops); + &vimc_deb_int_ops, &vimc_deb_ops); if (ret) { kfree(vdeb); return ret; diff --git a/drivers/media/platform/vimc/vimc-scaler.c b/drivers/media/platform/vimc/vimc-scaler.c index 39b2a73dfcc1..2028afa4ef7a 100644 --- a/drivers/media/platform/vimc/vimc-scaler.c +++ b/drivers/media/platform/vimc/vimc-scaler.c @@ -348,6 +348,18 @@ static void *vimc_sca_process_frame(struct vimc_ent_device *ved, return vsca->src_frame; }; +static void vimc_sca_release(struct v4l2_subdev *sd) +{ + struct vimc_sca_device *vsca = + container_of(sd, struct vimc_sca_device, sd); + + kfree(vsca); +} + +static const struct v4l2_subdev_internal_ops vimc_sca_int_ops = { + .release = vimc_sca_release, +}; + static void vimc_sca_comp_unbind(struct device *comp, struct device *master, void *master_data) { @@ -356,7 +368,6 @@ static void vimc_sca_comp_unbind(struct device *comp, struct device *master, ved); vimc_ent_sd_unregister(ved, &vsca->sd); - kfree(vsca); } @@ -379,7 +390,7 @@ static int vimc_sca_comp_bind(struct device *comp, struct device *master, MEDIA_ENT_F_PROC_VIDEO_SCALER, 2, (const unsigned long[2]) {MEDIA_PAD_FL_SINK, MEDIA_PAD_FL_SOURCE}, - &vimc_sca_ops); + &vimc_sca_int_ops, &vimc_sca_ops); if (ret) { kfree(vsca); return ret; diff --git a/drivers/media/platform/vimc/vimc-sensor.c b/drivers/media/platform/vimc/vimc-sensor.c index 59195f262623..d7891d3bbeaa 100644 --- a/drivers/media/platform/vimc/vimc-sensor.c +++ b/drivers/media/platform/vimc/vimc-sensor.c @@ -301,6 +301,20 @@ static const struct v4l2_ctrl_ops vimc_sen_ctrl_ops = { .s_ctrl = vimc_sen_s_ctrl, }; +static void vimc_sen_release(struct v4l2_subdev *sd) +{ + struct vimc_sen_device *vsen = + container_of(sd, struct vimc_sen_device, sd); + + v4l2_ctrl_handler_free(&vsen->hdl); + tpg_free(&vsen->tpg); + kfree(vsen); +} + +static const struct v4l2_subdev_internal_ops vimc_sen_int_ops = { + .release = vimc_sen_release, +}; + static void vimc_sen_comp_unbind(struct device *comp, struct device *master, void *master_data) { @@ -309,9 +323,6 @@ static void vimc_sen_comp_unbind(struct device *comp, struct device *master, container_of(ved, struct vimc_sen_device, ved); vimc_ent_sd_unregister(ved, &vsen->sd); - v4l2_ctrl_handler_free(&vsen->hdl); - tpg_free(&vsen->tpg); - kfree(vsen); } /* Image Processing Controls */ @@ -371,7 +382,7 @@ static int vimc_sen_comp_bind(struct device *comp, struct device *master, pdata->entity_name, MEDIA_ENT_F_CAM_SENSOR, 1, (const unsigned long[1]) {MEDIA_PAD_FL_SOURCE}, - &vimc_sen_ops); + &vimc_sen_int_ops, &vimc_sen_ops); if (ret) goto err_free_hdl;