Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp840956pxb; Thu, 28 Jan 2021 01:16:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzwVfqnkqDE83lzQbvMYZ469E3dXH412wwQI7SN78xJS2CMIPJ6trwHPj1OAIH/SFQ1iCD X-Received: by 2002:aa7:c2ce:: with SMTP id m14mr12634056edp.76.1611825360343; Thu, 28 Jan 2021 01:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611825360; cv=none; d=google.com; s=arc-20160816; b=dD4EtxlKxOzyNJcg5ZNvZNOKAr1nHJgO+TxM+QdbSNlDZXfxA6AbRqkDQ4ClkpvUlR Zupr06doQ0UOL1aSiVDKTMJuVrMFtmalGt0oWN8L8+EZHyhni9K7n9ub6ouJ8l+r2kFY J/eOzrPKH5mqIs/NwW/wfxkrkavAiyZLfLPlDLSu6wpgwwdrtPVcw+4Vax3v4Hp6Pvu+ XpJEbtmsm5kbjfWRlkVmt+oc6+NaX/a/NWFicKd0kxRC5609sJWDlqgbwtRLjb5QxEc2 yuqf2iNOpXrHIplpKEswFfpNESt9euuLcvZhCggt1RTxIdqr9eljaSPJ1XfOe1OwnA9b rv5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LkkghXLEZtKs2UasXTo29DZk2emRgHZTzWpBY3lc7cg=; b=kMBKahxn+i/qIEgQb5biYVz4uTiAgI87/l/2W+2c48SPu+pQiowUqmF2qpw6m4NVl2 bPyrtjZpxicUmX8VbFKgraKKglucmJye+QVyyNiXsVpmqdRhKyyBCwYZN9zL0QsfMdAR uSWgxkikTzsThn0jKW6qJ7fmDEfWpzhFAVogWTFwiMWQSKE7/XhKEPsanJkWGFV3tv68 NHWuthnAKoqEWMX9gKmfAltaLjY6Sw+8i1nwG/0fTqz+oKn3ReS6AGbHtIRoGzAyRYHY 40OeeOmqgabL5BqjylfHgjAW584yWcC2vMU7C0E+w3zrM3hTezR8tyrdz2iNotNhOfjM uyiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si2598789edp.472.2021.01.28.01.15.35; Thu, 28 Jan 2021 01:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbhA1JOS (ORCPT + 99 others); Thu, 28 Jan 2021 04:14:18 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:59289 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232164AbhA1JLe (ORCPT ); Thu, 28 Jan 2021 04:11:34 -0500 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=20Kleine-K=C3=B6nig?= To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , kernel@pengutronix.de 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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); -- 2.29.2