Re: Kernelnewbies Digest, Vol 79, Issue 18

2017-06-21 Thread Stan Drozd
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 
> #include 
> #include 
> #include 
> #include 
> #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=email,
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

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: My network device don't work

2017-06-20 Thread Stan Drozd
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

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies