<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 24, 2017 at 12:03 PM, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Feb 24, 2017 at 8:14 PM, Ben Chan <<a href="mailto:benchan@chromium.org">benchan@chromium.org</a>> wrote:<br>
>> > find_device_by_physdev_uid() expects a non-NULL UID of the physical<br>
>> > device. However, mm_kernel_device_get_physdev_<wbr>uid() could potentially<br>
>> > return NULL on MMKernelDeviceUdev if find_physical_gudevdevice() in<br>
>> > mm-kernel-device-udev.c fails to find the physical device. When a NULL<br>
>> > physical device UID is passed to find_device_by_physdev_uid() and used<br>
>> > in g_hash_table_lookup(), it leads to a crash in g_str_hash(), which is<br>
>> > a bit obscure.<br>
>> ><br>
>> > This patch updates find_device_by_physdev_uid() to handle the case when<br>
>> > mm_kernel_device_get_physdev_<wbr>uid() fails to return a valid UID, and also<br>
>> > moves the assertion on non-NULL UID to find_device_by_physdev_uid() in<br>
>> > order to ensure find_device_by_physdev_uid() is properly used by future<br>
>> > callers.<br>
>><br>
>> I'm not sure I agree with this patch. We do want to enforce non-NULL<br>
>> UIDs, as that UID (it previously was the "physdev sysfs path" but<br>
>> doesn't have to now) is used to group ports of the same device<br>
>> together. If the device exposes a single port and has no parent device<br>
>> per se, the sysfs path of the port itself may be used as UID, as<br>
>> there's no grouping to be done.<br>
>><br>
>> What we should make sure is that mm_kernel_device_get_physdev_<wbr>uid()<br>
>> never returns NULL, and so the g_assert() is correctly in place.<br>
>><br>
>> What do you think about these comments?<br>
>><br>
><br>
> If that's the expectation, the g_assert() should be placed inside<br>
> mm_kernel_device_get_physdev_<wbr>uid () instead of the call sites of<br>
> mm_kernel_device_get_physdev_<wbr>uid (), which is easier to omit.<br>
><br>
<br>
</div></div>I agree, yes.<br>
<span class=""><br>
> I can update the patch to move the g_assert () and modify the code to<br>
> provide a fallback value of physdev uid to ensure it's never NULL. WDYT?<br>
<br>
</span>Yes, that is a good idea.<br>
<br>
Something like this:<br>
<br>
 * If user-provided UID via "self->priv->properties", return that one.<br>
 * Otherwise, if user-provided UID via "ID_MM_PHYSDEV_UID", return that one.<br></blockquote><div><br></div><div>I believe that's what MMKernelDeviceGeneric currently does. However, MMKernelDeviceUdev tries to get ID_MM_PHYSDEV_UID on self->priv->physdev instead of self->priv->device. That's first discrepancy I noticed. Is that expected?</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 * Otherwise, if physdev is valid, return physdev sysfs path. This<br>
will be the most common case.<br>
 * Otherwise, if self->priv->device is set, return port sysfs path<br>
(kernel_device_get_sysfs_path(<wbr>)).<br>
 * Otherwise, the very unlikely case, just return port name.<br>
<br>
This would be the same order applied in the "generic" MMKernelDevice<br>
backend, but here we do require sysfs path of the port as a mandatory<br>
parameter and therefore the last very unlikely case above wouldn't<br>
apply.<br>
<br>
What do you think?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Aleksander<br>
<a href="https://aleksander.es" rel="noreferrer" target="_blank">https://aleksander.es</a><br>
</font></span></blockquote></div><br></div></div>