Re: make error in building sample code!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi :
sorry for pick up this old thread.

2009/8/4 Robert P. J. Day <rpjday@xxxxxxxxxxxxxx>:
> On Tue, 4 Aug 2009, Greg Peter wrote:
>
>> Hello,
>>
>> I am trying to build LDD3 sample code, just to get expirement around.
>> (Obtained from the link ->
>> http://oreilly.com.cn/codeexample/ldd3/examples.tar.gz).
>>
>> But I get the following errors when I run make: (PS note, I have the kernel
>> source and headers installed)
>>
>>
>> #examples> make
>> for n in misc-progs misc-modules skull scull scullc sculld scullp scullv
>> sbull snull short shortprint pci simple usb tty lddbus; do make -C $n ||
>> exit 1; done
>> make[1]: Entering directory `/home/gregp/examples/misc-progs'
>> cc -O2 -fomit-frame-pointer -Wall
>> -I/lib/modules/2.6.27.23-0.1-pae/build/include    setlevel.c   -o setlevel
>> setlevel.c:30: error: expected declaration specifiers or ?...? before ?syslog?
>> setlevel.c:30: error: expected declaration specifiers or ?...? before ?type?
>> setlevel.c:30: error: expected declaration specifiers or ?...? before ?bufp?
>> setlevel.c:30: error: expected declaration specifiers or ?...? before ?len?
>> setlevel.c:30: warning: data definition has no type or storage class
>> setlevel.c:30: warning: type defaults to ?int? in declaration of ?_syscall3?
>> setlevel.c: In function ?main?:
>> setlevel.c:41: warning: implicit declaration of function ?syslog?
>> make[1]: *** [setlevel] Error 1
>> make[1]: Leaving directory `/home/gregp/examples/misc-progs'
>> make: *** [subdirs] Error 1
>
>  those userspace programs still use the now-deprecated and
> unsupported _syscall macros.  they should be rewritten to use
> syscall() instead.  see:
>
> http://www.kernel.org/doc/man-pages/online/pages/man2/_syscall.2.html
>
I can compile the attach lddbus.c successfully but fail to insert the module.
it is because device_register return a non-zero value.
I have also checked other driver to compare the procedure of initial
"struct device", but I cannot see the difference.

take scsi_debug.c for example:
static struct device pseudo_primary = {
        .init_name      = "pseudo_0",
        .release        = pseudo_0_release,
};

static int __init scsi_debug_init(void)
{
......
        ret = device_register(&pseudo_primary);
        if (ret < 0) {
                printk(KERN_WARNING "scsi_debug: device_register error: %d\n",
                        ret);
                goto free_vm;
        }
.....
}

is there any CONFIG in kernel i should open for fixing this problem?

-- 
Regards,
/*
 * A virtual bus for LDD sample code devices to plug into.  This
 * code is heavily borrowed from drivers/base/sys.c
 *
 * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
 * Copyright (C) 2001 O'Reilly & Associates
 *
 * The source code in this file can be freely used, adapted,
 * and redistributed in source or binary form, so long as an
 * acknowledgment appears in derived source files.  The citation
 * should list that the code comes from the book "Linux Device
 * Drivers" by Alessandro Rubini and Jonathan Corbet, published
 * by O'Reilly & Associates.   No warranty is attached;
 * we cannot take responsibility for errors or fitness for use.
 *
 */
/* $Id: lddbus.c,v 1.9 2004/09/26 08:12:27 gregkh Exp $ */

#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/kdev_t.h>

#include "lddbus.h"

MODULE_AUTHOR("Jonathan Corbet");
MODULE_LICENSE("Dual BSD/GPL");
static char *Version = "$Revision: 1.9 $";

/*
 * Respond to udev events.
 */
static int ldd_uevent(struct device *dev, struct kobj_uevent_env *env)
{
	if (add_uevent_var(env,
			   "LDDBUS_VERSION=%s", Version))
		return -ENOMEM;

	return 0;
}

/*
 * Match LDD devices to drivers.  Just do a simple name test.
 */
static int ldd_match(struct device *dev, struct device_driver *driver)
{
	return !strncmp(dev_name(dev), driver->name, strlen(driver->name));
}


/*
 * The LDD bus device.
 */
static void ldd_bus_release(struct device *dev)
{
	printk(KERN_DEBUG "lddbus release\n");
}


struct device ldd_bus = {
	.release  = ldd_bus_release
};


/*
 * And the bus type.
 */
struct bus_type ldd_bus_type = {
	.name = "ldd",
	.match = ldd_match,
	.uevent  = ldd_uevent,
};

/*
 * Export a simple attribute.
 */
static ssize_t show_bus_version(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%s\n", Version);
}

static BUS_ATTR(version, S_IRUGO, show_bus_version, NULL);



/*
 * LDD devices.
 */

/*
 * For now, no references to LDDbus devices go out which are not
 * tracked via the module reference count, so we use a no-op
 * release function.
 */
static void ldd_dev_release(struct device *dev)
{ }

int register_ldd_device(struct ldd_device *ldddev)
{
	ldddev->dev.bus = &ldd_bus_type;
	ldddev->dev.parent = &ldd_bus;
	ldddev->dev.release = ldd_dev_release;
	dev_set_name(&ldddev->dev, "ldd0");
	return device_register(&ldddev->dev);
}
EXPORT_SYMBOL(register_ldd_device);

void unregister_ldd_device(struct ldd_device *ldddev)
{
	device_unregister(&ldddev->dev);
}
EXPORT_SYMBOL(unregister_ldd_device);

/*
 * Crude driver interface.
 */


static ssize_t show_version(struct device_driver *driver, char *buf)
{
	struct ldd_driver *ldriver = to_ldd_driver(driver);

	sprintf(buf, "%s\n", ldriver->version);
	return strlen(buf);
}
		

int register_ldd_driver(struct ldd_driver *driver)
{
	int ret;
	
	driver->driver.bus = &ldd_bus_type;
	ret = driver_register(&driver->driver);
	if (ret)
		return ret;
	driver->version_attr.attr.name = "version";
	driver->version_attr.attr.mode = S_IRUGO;
	driver->version_attr.show = show_version;
	driver->version_attr.store = NULL;
	return driver_create_file(&driver->driver, &driver->version_attr);
}

void unregister_ldd_driver(struct ldd_driver *driver)
{
	driver_unregister(&driver->driver);
}
EXPORT_SYMBOL(register_ldd_driver);
EXPORT_SYMBOL(unregister_ldd_driver);



static int __init ldd_bus_init(void)
{
	int ret;

	ret = bus_register(&ldd_bus_type);
	if (ret)
		return ret;
	if (bus_create_file(&ldd_bus_type, &bus_attr_version))
		printk(KERN_NOTICE "Unable to create version attribute\n");
	ldd_bus.devt = MKDEV(23, 0);
	ret = device_register(&ldd_bus);
	if (ret)
		printk(KERN_NOTICE "Unable to register ldd0\n");
	return ret;
}

static void ldd_bus_exit(void)
{
	device_unregister(&ldd_bus);
	bus_unregister(&ldd_bus_type);
}

module_init(ldd_bus_init);
module_exit(ldd_bus_exit);
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux