[PATCH] drm: fix sysfs symlinks between driver and module

From: Akinobu Mita
Date: Fri Mar 06 2015 - 07:59:30 EST


When registering drivers, the symlinks for mapping between driver
and module are created in sysfs. But the drm drivers registered
by drm_pci_init() create wrong symlinks, because correct owner
module of pci driver is not passed to pci_register_driver().

For example, the i915 driver creates the following wrong symlinks:

/sys/bus/pci/drivers/i915/module -> ../../../../module/drm
/sys/module/drm/drivers/pci:i915 -> ../../../bus/pci/drivers/i915

With this change, these symlinks are fixed:

/sys/bus/pci/drivers/i915/module -> ../../../../module/i915
/sys/module/i915/drivers/pci:i915 -> ../../../bus/pci/drivers/i915

Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
Cc: David Airlie <airlied@xxxxxxxx>
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
---
drivers/gpu/drm/drm_pci.c | 14 +++++++++-----
include/drm/drmP.h | 5 ++++-
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index fd29f03..e093a11 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -318,16 +318,19 @@ err_free:
EXPORT_SYMBOL(drm_get_pci_dev);

/**
- * drm_pci_init - Register matching PCI devices with the DRM subsystem
+ * __drm_pci_init - Register matching PCI devices with the DRM subsystem
* @driver: DRM device driver
* @pdriver: PCI device driver
+ * @owner: owner module of pdriver
+ * @mod_name: module name string
*
* Initializes a drm_device structures, registering the stubs and initializing
* the AGP device.
*
* Return: 0 on success or a negative error code on failure.
*/
-int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
+int __drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver,
+ struct module *owner, const char *mod_name)
{
struct pci_dev *pdev = NULL;
const struct pci_device_id *pid;
@@ -336,7 +339,7 @@ int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
DRM_DEBUG("\n");

if (driver->driver_features & DRIVER_MODESET)
- return pci_register_driver(pdriver);
+ return __pci_register_driver(pdriver, owner, mod_name);

/* If not using KMS, fall back to stealth mode manual scanning. */
INIT_LIST_HEAD(&driver->legacy_dev_list);
@@ -404,7 +407,8 @@ EXPORT_SYMBOL(drm_pcie_get_speed_cap_mask);

#else

-int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
+int __drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver,
+ struct module *owner, const char *mod_name)
{
return -1;
}
@@ -425,7 +429,7 @@ int drm_pci_set_unique(struct drm_device *dev,
}
#endif

-EXPORT_SYMBOL(drm_pci_init);
+EXPORT_SYMBOL(__drm_pci_init);

/**
* drm_pci_exit - Unregister matching PCI devices from the DRM subsystem
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index e928625..8a06d9d 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1034,7 +1034,10 @@ static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
}
void drm_pci_agp_destroy(struct drm_device *dev);

-extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
+extern int __drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver,
+ struct module *owner, const char *mod_name);
+#define drm_pci_init(driver, pdriver) \
+ __drm_pci_init(driver, pdriver, THIS_MODULE, KBUILD_MODNAME)
extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
#ifdef CONFIG_PCI
extern int drm_get_pci_dev(struct pci_dev *pdev,
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/