* My network device don't work
@ 2017-06-20 12:32 wiktoria.lewicka
2017-06-20 13:31 ` Stan Drozd
2017-06-20 14:12 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: wiktoria.lewicka @ 2017-06-20 12:32 UTC (permalink / raw)
To: kernelnewbies
Hello.
I write simple network device, but its don't work. Module is loading, loading, loading...
Code:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/string.h>
#define DEV_NAME "chwdp"
struct net_device my_netdev;
int init_my_net_dev(struct net_device *dev);
struct net_device_ops nops = {
.ndo_init = init_my_net_dev,
//.ndo_uninit = uninit_my_net_dev,
};
static int __init init_dev(void)
{
//my_netdev.netdev_ops = &nops;
int result;
if((netdev_boot_setup_check(&my_netdev))){
printk(KERN_ERR "NETDEV: setup error");
return 0;
}
strncpy(my_netdev.name, DEV_NAME, 5);
if((result = register_netdev(&my_netdev)))
printk(KERN_ERR "NETDEV: Error registering device");
printk("NETDEV: Device registered successfully");
return 0;
}
static void __exit remove_dev(void)
{
unregister_netdev(&my_netdev);
}
int init_my_net_dev(struct net_device *dev)
{
printk("INIT");
return 0;
}
module_init(init_dev);
module_exit(remove_dev);
^ permalink raw reply [flat|nested] 4+ messages in thread
* My network device don't work
2017-06-20 12:32 My network device don't work wiktoria.lewicka
@ 2017-06-20 13:31 ` Stan Drozd
2017-06-20 14:12 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Stan Drozd @ 2017-06-20 13:31 UTC (permalink / raw)
To: kernelnewbies
On Tue, Jun 20, 2017 at 02:32:31PM +0200, wiktoria.lewicka wrote:
> Hello.
> I write simple network device, but its don't work. Module is loading, loading, loading...
> Code:
> [...]
Hello,
"strncpy(my_netdev.name, DEV_NAME, 5)" only copies the 5 chars in "chwdp" without the null byte. You could bump it to 6
or maybe change 5 to IFNAMSIZ (the net_device.name's size) and then change the last byte to '\0' manually
^ permalink raw reply [flat|nested] 4+ messages in thread
* My network device don't work
2017-06-20 12:32 My network device don't work wiktoria.lewicka
2017-06-20 13:31 ` Stan Drozd
@ 2017-06-20 14:12 ` Greg KH
2017-06-20 23:35 ` Tobin C. Harding
1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2017-06-20 14:12 UTC (permalink / raw)
To: kernelnewbies
On Tue, Jun 20, 2017 at 02:32:31PM +0200, wiktoria.lewicka wrote:
> Hello.
> I write simple network device, but its don't work. Module is loading, loading, loading...
> Code:
>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/netdevice.h>
> #include <linux/string.h>
> #define DEV_NAME "chwdp"
>
> struct net_device my_netdev;
>
> int init_my_net_dev(struct net_device *dev);
>
> struct net_device_ops nops = {
> .ndo_init = init_my_net_dev,
> //.ndo_uninit = uninit_my_net_dev,
> };
>
> static int __init init_dev(void)
> {
> //my_netdev.netdev_ops = &nops;
> int result;
> if((netdev_boot_setup_check(&my_netdev))){
> printk(KERN_ERR "NETDEV: setup error");
> return 0;
Why are you returning success if there was an error?
And always try to use proper kernel coding style when writing kernel
code if you expect/want someone else to read it :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* My network device don't work
2017-06-20 14:12 ` Greg KH
@ 2017-06-20 23:35 ` Tobin C. Harding
0 siblings, 0 replies; 4+ messages in thread
From: Tobin C. Harding @ 2017-06-20 23:35 UTC (permalink / raw)
To: kernelnewbies
On Tue, Jun 20, 2017 at 10:12:34PM +0800, Greg KH wrote:
> On Tue, Jun 20, 2017 at 02:32:31PM +0200, wiktoria.lewicka wrote:
Expanding on Greg's response, the document you want to read is
Documentation/process/coding-style.rst
> > Hello.
> > I write simple network device, but its don't work. Module is loading, loading, loading...
> > Code:
> >
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/init.h>
> > #include <linux/netdevice.h>
> > #include <linux/string.h>
> > #define DEV_NAME "chwdp"
> >
> > struct net_device my_netdev;
> >
> > int init_my_net_dev(struct net_device *dev);
> >
> > struct net_device_ops nops = {
> > .ndo_init = init_my_net_dev,
Preferred indentation is 8 characters.
> > //.ndo_uninit = uninit_my_net_dev,
Prefer c89 comments.
> > };
> >
> > static int __init init_dev(void)
> > {
> > //my_netdev.netdev_ops = &nops;
> > int result;
> > if((netdev_boot_setup_check(&my_netdev))){
> > printk(KERN_ERR "NETDEV: setup error");
> > return 0;
>
> Why are you returning success if there was an error?
>
> And always try to use proper kernel coding style when writing kernel
> code if you expect/want someone else to read it :)
Also, you should run your code through scripts/checkpatch.pl. That
script will catch coding style issues for you and help you learn them.
Good luck,
Tobin.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-20 23:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-20 12:32 My network device don't work wiktoria.lewicka
2017-06-20 13:31 ` Stan Drozd
2017-06-20 14:12 ` Greg KH
2017-06-20 23:35 ` Tobin C. Harding
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).