From patchwork Thu Jan 28 09:10:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12058529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55703C433E0 for ; Mon, 1 Feb 2021 09:31:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD31D64E30 for ; Mon, 1 Feb 2021 09:31:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD31D64E30 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=21qXkESMWnFqe++aq14QWaIE/KkHKG2SV6+f841N/wo=; b=btSliWaSo4U1kyiqOErRF1OySx 74kzsfC+ZNP+rd7Dgt9vT/PfAsIVRxK09I3Hy+j4e8g9UT4Tu2FQi+UJjvMrT4Jt0JSMbqpFZUEUd 72am7cbbtAcceHRj0ceetmsjW72U4hHAC5BJTZsZZAZDjEaXzmx72HFtL3UA6H9engniyyRGG+v6N 24TRrwnDQv3oZadTyRQewsoJAEuEptNyZyg6JPfK228kKiJb54U4+n26WXDTQs1QnTyvXfnNAtb2p cmCnUZL+uONlW1EOk7zEvW3+WG6sxtK9QwjhKJypCtovIDpKba/12W7YETKoxXFg3+8Wgqb7OGKt0 qwwVNnrw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l6VY9-0007Ow-4x; Mon, 01 Feb 2021 09:31:13 +0000 Received: from metis.ext.pengutronix.de ([85.220.165.71]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l53M9-0008Aj-Pa for linux-i3c@lists.infradead.org; Thu, 28 Jan 2021 09:12:50 +0000 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l53K2-00069M-EB; Thu, 28 Jan 2021 10:10:38 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1l53K1-0006X5-6C; Thu, 28 Jan 2021 10:10:37 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Alexandre Belloni Subject: [PATCH 1/2] i3c: Handle drivers without probe or remove callback Date: Thu, 28 Jan 2021 10:10:31 +0100 Message-Id: <20210128091032.16952-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-i3c@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210128_041249_851993_79531719 X-CRM114-Status: GOOD ( 14.85 ) X-Mailman-Approved-At: Mon, 01 Feb 2021 04:31:10 -0500 X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org A registered driver without a probe callback doesn't make sense, so refuse to register such a driver. (Otherwise i3c_device_probe() yields a NULL pointer exception.) A driver without remove is possible, e.g. when all resources are freed using devm callbacks. So guard the call to driver->remove by a check for being non-NULL. Note that the only in-tree i3c driver (drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c) doesn't have a remove callback. Signed-off-by: Uwe Kleine-König --- drivers/i3c/device.c | 5 +++++ drivers/i3c/master.c | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c index bb8e60dff988..e92d3e9a52bd 100644 --- a/drivers/i3c/device.c +++ b/drivers/i3c/device.c @@ -262,6 +262,11 @@ int i3c_driver_register_with_owner(struct i3c_driver *drv, struct module *owner) drv->driver.owner = owner; drv->driver.bus = &i3c_bus_type; + if (!drv->probe) { + pr_err("Trying to register an i3c driver without probe callback\n"); + return -EINVAL; + } + return driver_register(&drv->driver); } EXPORT_SYMBOL_GPL(i3c_driver_register_with_owner); diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index b61bf53ec07a..57a4f699eb8d 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -326,11 +326,13 @@ static int i3c_device_remove(struct device *dev) { struct i3c_device *i3cdev = dev_to_i3cdev(dev); struct i3c_driver *driver = drv_to_i3cdrv(dev->driver); - int ret; + int ret = 0; - ret = driver->remove(i3cdev); - if (ret) - return ret; + if (driver->remove) { + ret = driver->remove(i3cdev); + if (ret) + return ret; + } i3c_device_free_ibi(i3cdev);