Im getting a linking error I dont understand :
GEN usr/initramfs_data.cpio.gz
AS usr/initramfs_data.o
LD usr/built-in.o
CC [M] drivers/char/scx200_gpio.o
In file included from drivers/char/scx200_gpio.c:10:
include/linux/cdev.h:24: warning: ‘struct inode’ declared inside
parameter list
include/linux/cdev.h:24: warning: its scope is only this definition or
declaration, which is probably not what you want
GEN .version
CHK include/linux/compile.h
...
System is 1453 kB
Kernel: arch/i386/boot/bzImage is ready (#4)
Building modules, stage 2.
MODPOST
WARNING: "cdev_put" [drivers/char/scx200_gpio.ko] undefined!
CC drivers/char/scx200_gpio.mod.o
LD [M] drivers/char/scx200_gpio.ko
I suspected an include order problem, so naturally Ive been looking there.
I continue to try to figure out what Ive missed but ask here,
hoping that somebody *just knows* ;-)
The include diffs are minimal :
--- ../linux-2.6.18-rc1/drivers/char/scx200_gpio.c 2006-07-06
13:19:16.000000000 -0600
+++ x1-1/drivers/char/scx200_gpio.c 2006-07-10 15:56:14.000000000 -0600
@@ -5,8 +5,8 @@
Copyright (c) 2001,2002 Christer Weinigel <wingel@xxxxxxxxxxxxxxx> */
-#include <linux/config.h>
#include <linux/device.h>
+#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/errno.h>
@@ -22,19 +22,20 @@
#include <linux/scx200_gpio.h>
#include <linux/nsc_gpio.h>
-#define NAME "scx200_gpio"
-#define DEVNAME NAME
+#define DRVNAME "scx200_gpio"
I'll admit to rather complete confusion ;
- <linux/fs.h> defines struct inode, so that warning on line 24 doesnt
make sense,
- and that parameter-list usage is struct inode *, ie pointer, which
could be opaque
in some usages. (which is I guess why its a warning)
- and if cdev.h really needed it, it would just be included, right ?
What have I missed ? should I be looking elsewhere ?
Can somebody apply the attached patch to -mm1,
to either refute or corroborate my problem ?
(and maybe even fix it :-[
tia
-jimc
diff -ruNp -X dontdiff -X exclude-diffs x1-0/drivers/char/scx200_gpio.c y1/drivers/char/scx200_gpio.c
--- x1-0/drivers/char/scx200_gpio.c 2006-07-06 13:19:16.000000000 -0600
+++ y1/drivers/char/scx200_gpio.c 2006-07-10 17:24:11.000000000 -0600
@@ -5,8 +5,8 @@
Copyright (c) 2001,2002 Christer Weinigel <wingel@xxxxxxxxxxxxxxx> */
-#include <linux/config.h>
#include <linux/device.h>
+#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/errno.h>
@@ -22,19 +22,20 @@
#include <linux/scx200_gpio.h>
#include <linux/nsc_gpio.h>
-#define NAME "scx200_gpio"
-#define DEVNAME NAME
+#define DRVNAME "scx200_gpio"
static struct platform_device *pdev;
MODULE_AUTHOR("Christer Weinigel <wingel@xxxxxxxxxxxxxxx>");
-MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver");
+MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO Pin Driver");
MODULE_LICENSE("GPL");
static int major = 0; /* default to dynamic major */
module_param(major, int, 0);
MODULE_PARM_DESC(major, "Major device number");
+#define MAX_PINS 32 /* 64 later, when known ok */
+
struct nsc_gpio_ops scx200_access = {
.owner = THIS_MODULE,
.gpio_config = scx200_gpio_configure,
@@ -46,13 +47,14 @@ struct nsc_gpio_ops scx200_access = {
.gpio_change = scx200_gpio_change,
.gpio_current = scx200_gpio_current
};
+EXPORT_SYMBOL(scx200_access);
static int scx200_gpio_open(struct inode *inode, struct file *file)
{
unsigned m = iminor(inode);
file->private_data = &scx200_access;
- if (m > 63)
+ if (m >= MAX_PINS)
return -EINVAL;
return nonseekable_open(inode, file);
}
@@ -62,7 +64,6 @@ static int scx200_gpio_release(struct in
return 0;
}
-
static const struct file_operations scx200_gpio_fops = {
.owner = THIS_MODULE,
.write = nsc_gpio_write,
@@ -71,21 +72,20 @@ static const struct file_operations scx2
.release = scx200_gpio_release,
};
-struct cdev *scx200_devices;
-static int num_pins = 32;
+struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
static int __init scx200_gpio_init(void)
{
- int rc, i;
- dev_t dev = MKDEV(major, 0);
+ int rc;
+ dev_t devid;
if (!scx200_gpio_present()) {
- printk(KERN_ERR NAME ": no SCx200 gpio present\n");
+ printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
return -ENODEV;
}
/* support dev_dbg() with pdev->dev */
- pdev = platform_device_alloc(DEVNAME, 0);
+ pdev = platform_device_alloc(DRVNAME, 0);
if (!pdev)
return -ENOMEM;
@@ -96,35 +96,23 @@ static int __init scx200_gpio_init(void)
/* nsc_gpio uses dev_dbg(), so needs this */
scx200_access.dev = &pdev->dev;
- if (major)
- rc = register_chrdev_region(dev, num_pins, "scx200_gpio");
- else {
- rc = alloc_chrdev_region(&dev, 0, num_pins, "scx200_gpio");
- major = MAJOR(dev);
+ if (major) {
+ devid = MKDEV(major, 0);
+ rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
+ } else {
+ rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
+ major = MAJOR(devid);
}
if (rc < 0) {
dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
goto undo_platform_device_add;
}
- scx200_devices = kzalloc(num_pins * sizeof(struct cdev), GFP_KERNEL);
- if (!scx200_devices) {
- rc = -ENOMEM;
- goto undo_chrdev_region;
- }
- for (i = 0; i < num_pins; i++) {
- struct cdev *cdev = &scx200_devices[i];
- cdev_init(cdev, &scx200_gpio_fops);
- cdev->owner = THIS_MODULE;
- rc = cdev_add(cdev, MKDEV(major, i), 1);
- /* tolerate 'minor' errors */
- if (rc)
- dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
- }
+
+ cdev_init(&scx200_gpio_cdev, &scx200_gpio_fops);
+ cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
return 0; /* succeed */
-undo_chrdev_region:
- unregister_chrdev_region(dev, num_pins);
undo_platform_device_add:
platform_device_del(pdev);
undo_malloc:
@@ -135,10 +123,12 @@ undo_malloc:
static void __exit scx200_gpio_cleanup(void)
{
- kfree(scx200_devices);
- unregister_chrdev_region(MKDEV(major, 0), num_pins);
+ cdev_del(&scx200_gpio_cdev);
+ cdev_put(&scx200_gpio_cdev);
+ /* WARNING: "cdev_put" [drivers/char/scx200_gpio.ko] undefined! */
+
+ unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
platform_device_unregister(pdev);
- /* kfree(pdev); */
}
module_init(scx200_gpio_init);