<div dir="ltr"><div><div><div>The problem we ran into was when we had a struct like this:<br><br></div>struct table {<br></div>   uint16_t size;<br></div>   struct element elements[0];<br><div><div>};<br><div><div><div class="gmail_extra"><br></div><div class="gmail_extra">and then we would try and index the array:<br><br></div><div class="gmail_extra">for (i = 0; i < table->size; i++) {<br></div><div class="gmail_extra">  element = &table->elements[i];<br></div><div class="gmail_extra">}<br><br></div><div class="gmail_extra">element ended up off in the weeds.  The only thing that seems to make some versions of gcc happy was pointer arithmetic.  E.g.,<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">element = (struct element *)((char *)&table->elements[0] + (sizeof(struct element) * i));<br><br></div><div class="gmail_extra">Alex<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 18, 2016 at 11:21 AM, StDenis, Tom <span dir="ltr"><<a href="mailto:Tom.StDenis@amd.com" target="_blank">Tom.StDenis@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Any modern GCC should support [0] at the tail of a struct.  This came up because when I was reading the code I saw they allocated 7 slots (plus the size of the struct) but then fill 8 slots.  It's just weird
<img alt="😊" style="vertical-align:bottom" src="cid:b9d342ca-4063-4b61-a23c-e54ecb4cfb09"></p>
<p><br>
</p>
<p>Using [0] in the struct and allocating for 8 entries makes more sense and is clearer to read.</p>
<p><br>
</p>
<p>Tom</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block;width:98%">
<div dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> Christian König <<a href="mailto:deathsimple@vodafone.de" target="_blank">deathsimple@vodafone.de</a>><br>
<b>Sent:</b> Thursday, August 18, 2016 11:17<br>
<b>To:</b> StDenis, Tom; amd-gfx list<br>
<b>Subject:</b> Re: tidy'ing up cz_hwmgr.c</font>
<div> </div>
</div><div><div class="h5">
<div>
<div>
<blockquote type="cite">
<div>Has a [1] array at the tail which is then kzalloc'ed with N-1 entries.  Shouldn't that just be a [0] with N entries allocated for clarity?</div>
</blockquote>
Actually the starting address of a dynamic array should be manually calculated instead of using [1] or [0].<br>
<br>
We had tons of problems with that because some gcc versions get this wrong and the atombios code used this as well.<br>
<br>
Alex how did we resolved such issues?<br>
<br>
Regards,<br>
Christian.<br>
<br>
Am 18.08.2016 um 16:26 schrieb StDenis, Tom:<br>
</div>
<blockquote type="cite">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Tidying up cz_hwmgr.c I noted a couple of things but first is </p>
<p><br>
</p>
<div><span style="font-family:"Courier New",monospace">static bool cz_dpm_check_smu_features(<wbr>struct pp_hwmgr *hwmgr,</span></div>
<div><span style="white-space:pre-wrap;font-family:"Courier New",monospace"></span><span style="font-family:"Courier New",monospace">unsigned long check_feature);</span></div>
<div><br>
</div>
<div>Which will return "true" if the smu call fails <b>or</b> the feature is set.  </div>
<div><br>
</div>
<div>The structure </div>
<div><br>
</div>
<div>
<div><span style="font-family:"Courier New",monospace">struct phm_clock_voltage_dependency_<wbr>table;</span></div>
</div>
<div><br>
</div>
<div>Has a [1] array at the tail which is then kzalloc'ed with N-1 entries.  Shouldn't that just be a [0] with N entries allocated for clarity?</div>
<div><br>
</div>
<div>Tom</div>
<div><br>
</div>
</div>
<br>
<fieldset></fieldset> <br>
<pre>______________________________<wbr>_________________
amd-gfx mailing list
<a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank">amd-gfx@lists.freedesktop.org</a>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/amd-gfx</a>
</pre>
</blockquote>
<p><br>
</p>
</div>
</div></div></div>
</div>
</div>

<br>______________________________<wbr>_________________<br>
amd-gfx mailing list<br>
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/amd-gfx</a><br>
<br></blockquote></div><br></div></div></div></div></div></div>