From patchwork Thu Jan 28 09:10:47 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: 12058531 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,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 DB7BBC433E6 for ; Mon, 1 Feb 2021 09:31:13 +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 4A7D064EAA for ; Mon, 1 Feb 2021 09:31:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A7D064EAA 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=C8FL5AAr1jjZ7aYva8PsDtqB8t p8k2sZOvqN0DsM1EHKR3pW5oLgdhA9/Mh3UMi4vo+bel610I/GABiile5h5zOV7IgZy4m4500gQ6F TAKIAh3SUUbdCQpG36vxfblhKdEuV1bABtVhY35ERG+/WzKG0KG6vgI3ShScFRqYr3jiJnsNZ4FFW 3CkxGytm2yd76gDa0E2eJbIGe5hIgH9nntTGxLbmKZLU31niui249eStAC44ZMX/lcBRJElRm7gBp maZl3dDrqoZIUfNyjH8ibHEUoGulJd9GgCx9vX7ds30t9m+v1D+MMSzPStg8pCXnLN5x76JJ29bXi qlMqZK/w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l6VY8-0007OY-Ir; Mon, 01 Feb 2021 09:31:12 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l53KI-0007sV-H4 for linux-i3c@lists.infradead.org; Thu, 28 Jan 2021 09:10:55 +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 1l53KF-0006C2-KP; Thu, 28 Jan 2021 10:10:51 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1l53KF-00071V-BB; Thu, 28 Jan 2021 10:10:51 +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:47 +0100 Message-Id: <20210128091048.17006-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_041054_595472_F4149AD4 X-CRM114-Status: GOOD ( 14.96 ) 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, kernel@pengutronix.de 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);