<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 18, 2021 at 5:38 PM Greg KH <<a href="mailto:greg@kroah.com">greg@kroah.com</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 Wed, Aug 18, 2021 at 05:03:07PM +0530, Lloyd wrote:<br>
> Hi,<br>
> <br>
> I am starting to write linux kernel mode code. I am on Ubuntu 20.04. I have<br>
> written the following code<br>
> <br>
> The line DynPage[i]=0; //CRASH causes a crash. Can you please guide on<br>
> the reason for the crash?<br>
> <br>
> Thanks a lot in advance,<br>
> Lloyd<br>
> <br>
> #pragma GCC push_options<br>
> #pragma GCC optimize("O0")<br>
<br>
Why are you using these options? Try removing them and see what<br>
happens.<br>
<br></blockquote><div><br></div><div>Thanks a lot Greg. Yes, the code works now. </div><div><br></div><div>The assignment inside the for loop (DynPage[i]=0) is not used anywhere below. I thought that, when the compiler optimizes the code, it can remove that line. I am writing a small benchmarking application. So, I don't want that line to be removed by the compiler. Is there a better way to achieve this?</div><div><br></div><div>I am also surprised to see that disabling compiler optimization for a function caused my code to crash!!</div><div><br></div><div> </div></div></div>