Re: Kernelnewbies Digest, Vol 79, Issue 18
Thank you all, I make some changes in my code, but its still not work. When my module is loading and loading I have a problems with connection with Internet- is it a matter of configuration? My changes: #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/netdevice.h> #include <linux/string.h> #define DEV_NAME "my_dev\n" struct net_device my_netdev; int init_mdev(struct net_device *dev); struct net_device_ops nops = { .ndo_init = init_mdev, /*.ndo_uninit = unin_mdev,*/ }; 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; } strcpy(my_netdev.name, DEV_NAME); 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_mdev(struct net_device *dev) { printk("INIT"); return 0; } module_init(init_dev); module_exit(remove_dev); W dniu 2017-06-20 18:00:02 użytkownik <kernelnewbies-request@kernelnewbies.org> napisał:
Send Kernelnewbies mailing list submissions to kernelnewbies@kernelnewbies.org
To subscribe or unsubscribe via the World Wide Web, visit https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies or, via email, send a message with subject or body 'help' to kernelnewbies-request@kernelnewbies.org
You can reach the person managing the list at kernelnewbies-owner@kernelnewbies.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Kernelnewbies digest..."
Today's Topics:
1. My network device don't work (wiktoria.lewicka) 2. Re: My network device don't work (Stan Drozd) 3. Re: My network device don't work (Greg KH)
----------------------------------------------------------------------
Message: 1 Date: Tue, 20 Jun 2017 14:32:31 +0200 From: "wiktoria.lewicka" <wiktoria.lewicka@vp.pl> Subject: My network device don't work To: "kernelnewbies@kernelnewbies.org" <kernelnewbies@kernelnewbies.org> Message-ID: <186270325-26e3212af6540c227a34d3cd3b5e0c56@pmq3v.m5r2.onet> Content-Type: text/plain; charset="utf-8"
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);
------------------------------
Message: 2 Date: Tue, 20 Jun 2017 15:31:29 +0200 From: Stan Drozd <drozdziak1@gmail.com> Subject: Re: My network device don't work To: "wiktoria.lewicka" <wiktoria.lewicka@vp.pl> Cc: kernelnewbies@kernelnewbies.org Message-ID: <20170620133128.GB1233@gmail.com> Content-Type: text/plain; charset=us-ascii
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
------------------------------
Message: 3 Date: Tue, 20 Jun 2017 22:12:34 +0800 From: Greg KH <greg@kroah.com> Subject: Re: My network device don't work To: "wiktoria.lewicka" <wiktoria.lewicka@vp.pl> Cc: "kernelnewbies@kernelnewbies.org" <kernelnewbies@kernelnewbies.org> Message-ID: <20170620141234.GA2599@kroah.com> Content-Type: text/plain; charset=us-ascii
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
------------------------------
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
End of Kernelnewbies Digest, Vol 79, Issue 18 *********************************************
On Wed, Jun 21, 2017 at 12:35:54PM +0200, wiktoria.lewicka wrote:
Thank you all, I make some changes in my code, but its still not work. When my module is loading and loading I have a problems with connection with Internet- is it a matter of configuration? My changes:
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/netdevice.h> #include <linux/string.h> #define DEV_NAME "my_dev\n"
struct net_device my_netdev;
int init_mdev(struct net_device *dev);
struct net_device_ops nops = { .ndo_init = init_mdev, /*.ndo_uninit = unin_mdev,*/ };
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; You might want to return a -1 here. Are you sure netdev_boot_setup_check() returns 0 on *un*successful return? That's what the ! seems to suggest. } strcpy(my_netdev.name, DEV_NAME); if((result = register_netdev(&my_netdev))) printk(KERN_ERR "NETDEV: Error registering device"); printk("NETDEV: Device registered successfully"); Both of the printk()'s above will execute on error. How about adding braces and returning result on error? return 0; }
static void __exit remove_dev(void) { unregister_netdev(&my_netdev); } int init_mdev(struct net_device *dev) { printk("INIT"); return 0; } module_init(init_dev); module_exit(remove_dev);
It seems that your e-mail client (the Onet WebUI) keeps malforming your indentation. This link might come in handy: https://www.kernel.org/doc/html/v4.10/process/email-clients.html?highlight=e..., I'm sure more people will join the discussion once your style looks more approachable. I'm not much into network devices myself, but could you maybe try and find which call hangs your init function e.g. with printk()'s before each call? I believe your net_device structure might be incomplete. Once you find the problematic call, a cross-reference source code search engine like lxr.free-electrons.com/ could help you understand which struct net_device members might need your attention. Stan
participants (2)
-
Stan Drozd -
wiktoria.lewicka