From patchwork Fri Aug 31 15:20:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 51819 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fvlEN-0000Ga-BR; Fri, 31 Aug 2018 15:21:03 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727683AbeHaT2y (ORCPT + 1 other); Fri, 31 Aug 2018 15:28:54 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33421 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727286AbeHaT2y (ORCPT ); Fri, 31 Aug 2018 15:28:54 -0400 Received: by mail-wr1-f67.google.com with SMTP id v90-v6so11586346wrc.0 for ; Fri, 31 Aug 2018 08:20:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TyoCTa8EMpKGM+YX+iYdLQKMVHxr1N7PsqhbZhZaE4w=; b=DgYT6c++wBLAKWOtU2yNsWA9dj62ngeHrFMDJVUCW6SGM8KmoEjoq4CUOuqDAgCOas hZ03Z4o1pEA9E6KVyEbCCYSqSELpThepO6YwofBSGMY5Jq3ickpigwUkG31ulnzTpUkY pMilYsZ6l960ta0+77J9gnUN/TOGsf8dzSWobTQFech6xmB2zTb9l/YXsBampa064VP4 8GlfqjGnAZG5MrqrUlgIKQWta6ca3y1kSQIdhY3BxoJTuUHcGui0lXS+wNqVc+SF1ymj vmknHWgwFG/D7jnXCx7xh09wZ57ca2Z7mIYXqbOxyZA3y9EVZUPmZz0DLRy69fklEARU fM2g== X-Gm-Message-State: APzg51CDfEHIU98NdaEiH1J8HQ1jp6+Npp76VTXGiARVtuPHqrC7l/1Y 13i81mGIW1Y7fhdgT9Xl6J3DpZrQIWU= X-Google-Smtp-Source: ANB0VdZNBbbkCHtbaSU563YBTO7Kqko/IbAlJvt3QHZcZeAU6RKYnOhDG4LPaQ0YFfXCk7ZHpQ+Udg== X-Received: by 2002:a5d:428a:: with SMTP id k10-v6mr305354wrq.225.1535728854562; Fri, 31 Aug 2018 08:20:54 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id n17-v6sm3244923wmc.13.2018.08.31.08.20.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 08:20:53 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Javier Martinez Canillas , Mauro Carvalho Chehab , Tian Shu Qiu , Jian Xu Zheng , Sakari Ailus , Yong Zhi , Bingbu Cao , linux-media@vger.kernel.org Subject: [PATCH] media: intel-ipu3: cio2: register the mdev on v4l2 async notifier complete Date: Fri, 31 Aug 2018 17:20:45 +0200 Message-Id: <20180831152045.9957-1-javierm@redhat.com> X-Mailer: git-send-email 2.17.1 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Commit 9832e155f1ed ("[media] media-device: split media initialization and registration") split the media_device_register() function in two, to avoid a race condition that can happen when the media device node is accessed by userpace before the pending subdevices have been asynchronously registered. But the ipu3-cio2 driver calls the media_device_register() function right after calling media_device_init() which defeats the purpose of having two separate functions. In that case, userspace could have a partial view of the media device if it opened the media device node before all the pending devices have been bound. So instead, only register the media device once all pending v4l2 subdevices have been registered. Fixes: 9832e155f1ed ("media: intel-ipu3: cio2: add new MIPI-CSI2 driver") Signed-off-by: Javier Martinez Canillas --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 29027159eced..d936f3426c4e 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -1468,7 +1468,14 @@ static int cio2_notifier_complete(struct v4l2_async_notifier *notifier) } } - return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev); + ret = v4l2_device_register_subdev_nodes(&cio2->v4l2_dev); + if (ret) { + dev_err(&cio2->pci_dev->dev, + "failed to register V4L2 subdev nodes (%d)\n", ret); + return ret; + } + + return media_device_register(&cio2->media_dev); } static const struct v4l2_async_notifier_operations cio2_async_ops = { @@ -1792,16 +1799,12 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, cio2->media_dev.hw_revision = 0; media_device_init(&cio2->media_dev); - r = media_device_register(&cio2->media_dev); - if (r < 0) - goto fail_mutex_destroy; - cio2->v4l2_dev.mdev = &cio2->media_dev; r = v4l2_device_register(&pci_dev->dev, &cio2->v4l2_dev); if (r) { dev_err(&pci_dev->dev, "failed to register V4L2 device (%d)\n", r); - goto fail_media_device_unregister; + goto fail_media_device_cleanup; } r = cio2_queues_init(cio2); @@ -1831,10 +1834,8 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, cio2_queues_exit(cio2); fail_v4l2_device_unregister: v4l2_device_unregister(&cio2->v4l2_dev); -fail_media_device_unregister: - media_device_unregister(&cio2->media_dev); +fail_media_device_cleanup: media_device_cleanup(&cio2->media_dev); -fail_mutex_destroy: mutex_destroy(&cio2->lock); cio2_fbpt_exit_dummy(cio2);