From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754256AbbLJMmP (ORCPT ); Thu, 10 Dec 2015 07:42:15 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:36543 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754029AbbLJMmF (ORCPT ); Thu, 10 Dec 2015 07:42:05 -0500 From: Archit Taneja To: dri-devel@lists.freedesktop.org, a.hajda@samsung.com, jani.nikula@linux.intel.com Cc: linux-kernel@vger.kernel.org, airlied@linux.ie, daniel@ffwll.ch, treding@nvidia.com, l.stach@pengutronix.de, robh@kernel.org, linux-arm-msm@vger.kernel.org, Archit Taneja Subject: [PATCH v4 4/6] drm/dsi: Check for used channels Date: Thu, 10 Dec 2015 18:11:38 +0530 Message-Id: <1449751300-2841-5-git-send-email-architt@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1449751300-2841-1-git-send-email-architt@codeaurora.org> References: <1448884892-7731-1-git-send-email-architt@codeaurora.org> <1449751300-2841-1-git-send-email-architt@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't check whether a previously registered mipi_dsi_device under the same host shares the same virtual channel. Before registering, check if any of the registered devices doesn't already have the same virtual channel. This wasn't crucial when all the devices under a host were populated via DT. Now that we also support creating devices manually, we could end up in a situation where a driver tries to create a device with a virtual channel already taken by a device populated in DT. Reviewed-by: Andrzej Hajda Signed-off-by: Archit Taneja --- drivers/gpu/drm/drm_mipi_dsi.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index 5a46802..7a81171 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -119,6 +119,22 @@ static const struct device_type mipi_dsi_device_type = { .release = mipi_dsi_dev_release, }; +static int __dsi_check_chan_busy(struct device *dev, void *data) +{ + struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); + u32 *reg = data; + + if (dsi && dsi->channel == *reg) + return -EBUSY; + + return 0; +} + +static int mipi_dsi_check_chan_busy(struct mipi_dsi_host *host, u32 reg) +{ + return device_for_each_child(host->dev, ®, __dsi_check_chan_busy); +} + struct mipi_dsi_device *mipi_dsi_device_new(struct mipi_dsi_host *host, struct mipi_dsi_device_info *info) { @@ -146,14 +162,20 @@ struct mipi_dsi_device *mipi_dsi_device_new(struct mipi_dsi_host *host, dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), info->reg); + ret = mipi_dsi_check_chan_busy(host, info->reg); + if (ret) + goto err; + ret = device_register(&dsi->dev); if (ret) { dev_err(dev, "failed to register device: %d\n", ret); - kfree(dsi); - return ERR_PTR(ret); + goto err; } return dsi; +err: + kfree(dsi); + return ERR_PTR(ret); } EXPORT_SYMBOL(mipi_dsi_device_new); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation