Skip to contentSkip to conversation

spmi: Drop struct spmi_device_id

PATCH New Uwe Kleine-König 1 participant 4 messages Nov 26 SPMI

lore
Share & tools
lore
#0 lore raw

v2 cover spmi: Drop struct spmi_device_id

Hello,

my v1 patch
(https://lore.kernel.org/all/[email protected]/)
is the same as patch #2 here, but without the first patch of this series this results in a build failure. I kept Pawel's R-b tag I got in v1.

I'm not 100% sure, I grokked the spmi situation completely. As pointed out in the commit description of patch #1 both driver name and device name are proper \0-terminated strings with no theoretical length limit. So only comparing SPMI_NAME_SIZE chars is at least strange. I think there is no device/driver combo that needs that string comparison to match.

All spmi devices seem to be instantiated via drivers/spmi/spmi.c from dtb with the exception of drivers/regulator/mt6363-regulator.c. spmi_device_add() enforces a device name in the form format("%d-%02x", sdev->ctrl->nr, sdev->usid) and I didn't find a driver with that name. mt6363-regulator.c does

	sdev = spmi_device_alloc(sparent->ctrl);
	dev_set_name(&sdev->dev, "%d-%02x-regulator", sdev->ctrl->nr, sdev->usid);
	device_add(&sdev->dev);

but there doesn't seem to be a matching driver for that either.

I discovered the opportunity for the 3rd patch while researching the above details. I'm not sure about that either as drivers/regulator/mt6363-regulator.c uses spmi_device_remove() so maybe it should use spmi_device_add(), too? Also I didn't find the device_put() that is needed to undo spmi_device_alloc() when the mt6363-regulator device gets unbound.

Best regards
Uwe

Uwe Kleine-König (3):
spmi: Don't limit device name matchin driver name on SPMI_NAME_SIZE
chars
spmi: Drop struct spmi_device_id
spmi: Don't export locally used function spmi_device_add()

 drivers/spmi/spmi.c             |  6 ++----
 include/linux/device-id/spmi.h  | 17 -----------------
 include/linux/mod_devicetable.h |  1 -
 include/linux/spmi.h            |  2 --
 4 files changed, 2 insertions(+), 24 deletions(-)
 delete mode 100644 include/linux/device-id/spmi.h

base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7

Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/3 spmi: Don't limit device name matchin driver name on SPMI_NAME_SIZE chars

Both device name and driver name are not limited to SPMI_NAME_SIZE chars and both are always properly \0-terminated. So it doesn't make sense to use strncmp() here. Use strcmp() instead.

---
 drivers/spmi/spmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spmi/spmi.c +1 -2
index ec97f12046f5..6d6805a5ae69 100644
@@ -64,8 +64,7 @@ static int spmi_device_match(struct device *dev, const struct device_driver *drv
 		return 1;
 
 	if (drv->name)
-		return strncmp(dev_name(dev), drv->name,
-			       SPMI_NAME_SIZE) == 0;
+		return strcmp(dev_name(dev), drv->name) == 0;
 
 	return 0;
 }
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/3 spmi: Drop struct spmi_device_id

In reply to Uwe Kleine-König

This was introduced by commit 5a86bf343976 ("spmi: Linux driver framework for SPMI") in 2014 for Linux 3.15 and already then was unused and no user was added since then. The only exception was a usage of SPMI_NAME_SIZE that was dropped in the previous commit.

---
 include/linux/device-id/spmi.h  | 17 -----------------
 include/linux/mod_devicetable.h |  1 -
 2 files changed, 18 deletions(-)
 delete mode 100644 include/linux/device-id/spmi.h
include/linux/device-id/spmi.h deleted +0 -17
deleted file mode 100644
index a821c42cfc9a..000000000000
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef LINUX_DEVICE_ID_SPMI_H
-#define LINUX_DEVICE_ID_SPMI_H
-
-#ifdef __KERNEL__
-typedef unsigned long kernel_ulong_t;
-#endif
-
-#define SPMI_NAME_SIZE	32
-#define SPMI_MODULE_PREFIX "spmi:"
-
-struct spmi_device_id {
-	char name[SPMI_NAME_SIZE];
-	kernel_ulong_t driver_data;	/* Data private to the driver */
-};
-
-#endif /* ifndef LINUX_DEVICE_ID_SPMI_H */
include/linux/mod_devicetable.h +0 -1
index a69947f2c1dc..fd21238c99f5 100644
@@ -51,7 +51,6 @@
 #include "device-id/serio.h"
 #include "device-id/slim.h"
 #include "device-id/spi.h"
-#include "device-id/spmi.h"
 #include "device-id/ssam.h"
 #include "device-id/ssb.h"
 #include "device-id/tb.h"
Signature · 1 line
2.47.3
#3 lore raw

PATCH v2 3/3 spmi: Don't export locally used function spmi_device_add()

In reply to Uwe Kleine-König

drivers/spmi/spmi.c is the only user of spmi_device_add(). So there is no need to export this function for module usage.

---
 drivers/spmi/spmi.c  | 3 +--
 include/linux/spmi.h | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/spmi/spmi.c +1 -2
index 6d6805a5ae69..c8b3e236db83 100644
@@ -73,7 +73,7 @@ static int spmi_device_match(struct device *dev, const struct device_driver *drv
  * spmi_device_add() - add a device previously constructed via spmi_device_alloc()
  * @sdev:	spmi_device to be added
  */
-int spmi_device_add(struct spmi_device *sdev)
+static int spmi_device_add(struct spmi_device *sdev)
 {
 	struct spmi_controller *ctrl = sdev->ctrl;
 	int err;
@@ -89,7 +89,6 @@ int spmi_device_add(struct spmi_device *sdev)
 	dev_dbg(&sdev->dev, "device registered\n");
 	return 0;
 }
-EXPORT_SYMBOL_GPL(spmi_device_add);
 
 /**
  * spmi_device_remove(): remove an SPMI device
include/linux/spmi.h +0 -2
index 4daebc980501..c81ff3eb8cbe 100644
@@ -65,8 +65,6 @@ static inline void spmi_device_put(struct spmi_device *sdev)
 		put_device(&sdev->dev);
 }
 
-int spmi_device_add(struct spmi_device *sdev);
-
 void spmi_device_remove(struct spmi_device *sdev);
 
 /**
Signature · 1 line
2.47.3