GNOME Bugzilla – Bug 759261
[review] platform cleanup [th/platform-api-cleanup-bgo759261]
Last modified: 2015-12-10 13:48:58 UTC
After moving platform away from libnl-route-3 and adding support for new device types, do some refactoring and cleanup. Refactoring is often problematic because it makes backporting harder. But at this point, platform deviated so far from nm-1-0 that we likely won't backport much anymore. The time is now.
> platform: return pointer to NMPlatformLink object for add functions /* Create any resources the device needs */ if (NM_DEVICE_GET_CLASS (self)->create_and_realize) { if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error)) return FALSE; + plink_copy = *plink; + plink = &plink_copy; } - NM_DEVICE_GET_CLASS (self)->setup_start (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); - nm_device_setup_finish (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); + NM_DEVICE_GET_CLASS (self)->setup_start (self, plink); + nm_device_setup_finish (self, plink) I wonder if the copy is necessary... isn't the pointer supposed to be valid through the whole function? But probably we can't be sure that setup_start() and setup_finish() will not call any platform operations which could invalidate the link. So LGTM, as the rest of patches.
Exactly, the pointer is only guaranteed to be valid until the next nm_platform_*() operation. It's not clear that setup_start()/setup_finish() doesn't do something that might invalidate the pointer, so we copy it. Note that the lnk objects are guaranteed not to be modified by platform. Hence, with a NMPlatformLnk* object you could take an additional reference to the object. Other platform objects (Link,IPxAddress,IPxRoute) are modified while they are cached. So, while we could do: nm_auto_nmpobj NMPObject *link_keep_alive = NULL; link_keep_alive = nmp_object_ref (NMP_OBJECT_UP_CAST (plink)); to keep plink alive, the content might still be modified by later platform operations.
merged: http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=9bc7b295a4a32cffa41f25fac3fa7846b2904ea2