Received: by 10.192.165.156 with SMTP id m28csp2046026imm; Thu, 12 Apr 2018 07:46:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/f4ZTLO4sxgfVIPkn5jBA+z6KQKhHQnO7rywLAsBmqf3/dvVnOsgxf3mePR9p5K227AnLs X-Received: by 10.99.120.74 with SMTP id t71mr966735pgc.310.1523544373593; Thu, 12 Apr 2018 07:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523544373; cv=none; d=google.com; s=arc-20160816; b=dgqmLpjVk4IWvMMQya/2yAGG+Fbt3Tbj+BB96r7vklP9jyI7HGm+ELo/uoX1ASeBXb 9ATEm5FknW5ozP3jNSLwcZiRzV9NDO5q5ITfHTACD0+H3N3sjGpBrOJ5iJ2dxbapvqS8 ZS5Ruvuiyulp6yY3baY/ixONZSYRMkPyCiQfX4yM2bVosiIopyiSRQ1+pRFj3OjIwrtU 1Gay8Y6FU9/l1MfPi5vJu5XsxurfmSU30MarlTxtlCTkMm7EiAHQvGknIekqjZnyBpSR 2I5cd6yiR0TkM8gsiRhclB4W8s+gJLlkAaU6MKslCCiHaADyZdLfYIXQi7d5yRUB2nAT pF+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:nodisclaimer:mime-version:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XtLO6cJJI0dOCgaREgvY1m+GDip0UngYkSUucPpkRec=; b=AqIiCbFQrvrO9WV2iVHDZZSJX+JxDcDQpZhYUuDVmAx8IX1zWx/mmk7u72YJmSfu7J V5heTm0K6wv8/a2NUjZhVzZOo9Al2HbqEWgmE/aMy/ZdE0fZ3ZTcOq/SfNWRE+ouW1jD VmgdtmsuW7xVTbk2cEU3RLHry1dOScrK6NvA+I9pkJAF7a1I3Lpo8zpt4MdCFQDRH7On 5graUbj8sLpWtlkm2IvQvauWFRegRMWHTUzohZSpV9HoB/BTcVSkud5Z2Kso+yU6jUe/ 8MREN2l/CiGMBBMQhKIivUZAFE8xmF/BNi9MdaCrSXaEi6B+2ycrKfroD9AUybp9rkzd 7hXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector1-arm-com header.b=F1oH1HHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u196si2324979pgc.384.2018.04.12.07.45.35; Thu, 12 Apr 2018 07:46:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector1-arm-com header.b=F1oH1HHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752793AbeDLOmq (ORCPT + 99 others); Thu, 12 Apr 2018 10:42:46 -0400 Received: from mail-db5eur01on0083.outbound.protection.outlook.com ([104.47.2.83]:44690 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752355AbeDLOmp (ORCPT ); Thu, 12 Apr 2018 10:42:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XtLO6cJJI0dOCgaREgvY1m+GDip0UngYkSUucPpkRec=; b=F1oH1HHRmr+2EK4X1ul6369MQXNI3wwhsMvtbuo/kVeF0PxEhj7hu03hTQgamtO+QImujA55APNq4xNTZtgyG6ZOvvhcdgaBfFiVyHlS/a+dZ4LE+k1ve0xtDBgus3RI9XFU5LkkCVoaMCWGQIH9uWkx5+GAXmLpNJHav/7p0ow= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ayan.Halder@arm.com; Received: from e113505-lin.cambridge.arm.com (217.140.96.140) by AM0PR08MB3026.eurprd08.prod.outlook.com (2603:10a6:208:5c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Thu, 12 Apr 2018 14:42:42 +0000 From: Ayan Kumar Halder To: ayan.halder@arm.com, liviu.dudau@arm.com, brian.starkey@arm.com, linux@armlinux.org.uk, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, alexandru-cosmin.gheorghe@arm.com Cc: nd@arm.com Subject: [PATCH] tda998x: Check ref count before invoking drm_connector_cleanup in unbind Date: Thu, 12 Apr 2018 15:42:32 +0100 Message-Id: <1523544152-15241-1-git-send-email-ayan.halder@arm.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: AM6PR0502CA0013.eurprd05.prod.outlook.com (2603:10a6:209:1::26) To AM0PR08MB3026.eurprd08.prod.outlook.com (2603:10a6:208:5c::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(48565401081)(2017052603328)(7153060)(7193020);SRVR:AM0PR08MB3026; X-Microsoft-Exchange-Diagnostics: 1;AM0PR08MB3026;3:U7Rh/zInovWu0Dk1rrqzhfMH2wgX51MCOGsED654t3xz7zjyqR0bUDURdISan2aFrWE7MfRjfmFbu0w0DD/CRUJwjreeTpU4OUztgrvTB2CxcQ/5NSlm74PSmewJBs27+1v63wVviw1b2MR8cdFzcaJJNw4c6Ugnv0fyrtIRJno7wUTZ4hc2/nnVFcVMUTQxPUY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/Oy1k+DZrBjPM5MHO3euFqRxsnyex4ujXfVK3DQmSRY9KMUtxbiMU3ZdyNWYLQA8tZoLdTAiP2rMHGR4b95rdhFky6/GXIbzWPmZ8QqvnwoaNLEmfbsLAyvPFx1Wueajo/6VvVSRfxmSlhYPBENBtOCtKhn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041310)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:AM0PR08MB3026;BCL:0;PCL:0;RULEID:;SRVR:AM0PR08MB3026; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(346002)(39380400002)(376002)(39840400004)(396003)(189003)(199004)(72206003)(8676002)(52116002)(2906002)(26005)(4326008)(51416003)(25786009)(316002)(7696005)(16586007)(386003)(53936002)(106356001)(478600001)(8936002)(81156014)(6636002)(6666003)(50226002)(81166006)(6486002)(68736007)(3846002)(486006)(36756003)(86362001)(97736004)(5660300001)(1857600001)(47776003)(7736002)(956004)(50466002)(105586002)(48376002)(6116002)(16526019)(476003)(66066001)(2616005)(305945005);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR08MB3026;H:e113505-lin.cambridge.arm.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM0PR08MB3026;23:qh9569PzRqDkl/AHqfHNJG2DVcLUubCcyheJ/85s0?= =?us-ascii?Q?xmxJPoIgWY1hBVqyyCTU/hxRo82AEPjGpEPlBTU6Y9EIUwDu2BqmQAYrb8ev?= =?us-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8mEXB7vXKwI44wA0Fvqjxkpw3Ys=;24:gycik3sflrVLMLfouwg5VKboCMp6TlofL2hiRNZM9WBRgjBYXM005HpKMfT3pwRVMB2hpUysK4tGIkly9kP6Lijfzji2A3G139N9qcaivWs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM0PR08MB3026;7:1zGf2eMlkELDk8JTAgLenaZVvOoxAB0q3sl8m0MiOfJxByIF/XGgXJxdg0c7PPNRiulx27TYbSWrO6YJTV+4wN0/vPWh66DSb14XdTrqp5khUTy5M5wJN/V8A+osaXumApgB1NiTbByf1jLb2YApuEnte5RB9SYHP569w4BReOXcZ/XPiqMWkKGAhIK/GtkuBDlAz+I9O4Ipaat3QfcelsmEpPgbBe0td2AB4SfgssVdntuxmOQ6biSzkpW5Fni5 X-MS-Office365-Filtering-Correlation-Id: 130f9a7b-9fbb-4c4b-bcbe-08d5a083a5b0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2018 14:42:42.1276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 130f9a7b-9fbb-4c4b-bcbe-08d5a083a5b0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3026 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In a situation when the reference count of the drm connector is greater than 1, the unbind function should not invoke drm_connector_cleanup as this will lead to an inconsistent state where the drm_crtc_state->connector_mask still has a bitmask referring to the stale connector. Later, when drm driver invokes drm_atomic_helper_shutdown() which invokes ---> drm_atomic_helper_disable_all() ---> drm_atomic_commit() --> drm_atomic_check_only() --> drm_atomic_helper_check() --> drm_atomic_helper_check_modeset(). This returns an error due to enabled/connectors mismatch. In such a scenario, one should just return from _unbind() and let the drm driver subsequently invoke drm_atomic_helper_shutdown. This will reset the drm_crtc_state->connector_mask and will shutdown the crtcs. It will also decrement the reference count of the connectors to 1. Subsequently, drm_mode_config_cleanup will get invoked which will do the following :- 1. Decrement the reference count for each of the connectors. Thus the ref count will reach 0 and drm_connector_funcs->destroy() gets called. Thus, tda998x_connector_destroy() gets invoked which calls drm_connector_cleanup 2. Invokes the destroy callback for each encoder. Thus tda998x_encoder_destroy() gets invoked. Signed-off-by: Ayan Kumar Halder --- drivers/gpu/drm/i2c/tda998x_drv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index 9e67a7b..8ad1cc7 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c @@ -1709,6 +1709,9 @@ static void tda998x_unbind(struct device *dev, struct device *master, { struct tda998x_priv *priv = dev_get_drvdata(dev); + if (kref_read(&priv->connector.base.refcount) > 1) + return; + drm_connector_cleanup(&priv->connector); drm_encoder_cleanup(&priv->encoder); tda998x_destroy(priv); -- 2.7.4