<div dir="ltr">Thank you very much. I am trying to rewrite the code. and fix these issues. <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 5, 2019 at 7:43 PM Valdis Klētnieks <<a href="mailto:valdis.kletnieks@vt.edu">valdis.kletnieks@vt.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 05 Nov 2019 17:59:43 +0900, Irfan Ullah said:<br>
<br>
> Thank you for the response.<br>
> Attached are the files for kernel-user spaces communication.<br>
<br>
> //when I remove this wait the code does not work<br>
> msleep(3000);<br>
<br>
If your code doesn't work, but sticking in random delays makes<br>
it start working, you almost certainly have a race condition or<br>
synchronization issue that should be fixed using proper locking.<br>
<br>
> void hello_exit(void)<br>
> {<br>
> //netlink_kernel_release(nl_sk);<br>
<br>
Congratulations. You just leaked a socket here, which is going to<br>
make it difficult to use that socket until you either reboot or find a<br>
way to close it properly before trying to create it again.<br>
<br>
> (code generates some warnings, but it is not severe and could be ignored for the time being).<br>
<br>
You should do the following:<br>
1) Understand your code well enough so you understand *why* the compiler<br>
issued the warning.<br>
2) Correct your code so the compiler doesn't complain. It almost certainly<br>
understands C better than you do.<br>
<br>
gcc 9.2.1 emits one warning on the kernel module code at default warning<br>
levels. And it's one you *really* need to fix, because it indicates that you<br>
and the compiler are not on the same page about what types your variables are.<br>
Since it's going to go ahead and generate code based on what types *it* thinks<br>
your variables are, you will have nothing but pain and anguish debugging if<br>
you thought they were some other type....<br>
<br>
In fact, you may want to compile the kernel module with 'make W=1' to get more<br>
warnings. If your system has sparse, you should use 'make W=1 C=1'.<br>
<br>
And all the warnings this generates are things that shouldn't be seen in clean<br>
kernel code.<br>
<br>
I didn't bother looking closely at your userspace. I gave up<br>
when I saw this:<br>
<br>
14 int sock_fd;<br>
(...)<br>
68 void user_space_receiver()<br>
69 {<br>
(...)<br>
96 user_space_receiver(sock_fd);<br>
<br>
There's 2 basic ways to pass a variable to a function. You're trying<br>
to use both of them here. Pick one and use it properly.<br>
<br>
Oh - and there's no possible way to reach the close(sock_fd); on line<br>
77, because the rest of the function infinite loops without a break. At the<br>
very least, you should be checking the return code from recvmsg() and<br>
exiting the while(1) loop if there's an issue.<br>
<br>
Bottom line: You need to get a *lot* more experience writing proper<br>
C code in userspace before you try to write kernel code.<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family: arial, sans-serif; font-size: 12.8px;"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size: 12.8px;"><span style="font-size:12.8px"><font color="#000000"> </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size: 12.8px;"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div>