mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 21:10:08 +01:00
initrd: use cleanup attribute in nmi_dt_reader_parse()
This commit is contained in:
parent
321a323df4
commit
e7cf22be3e
1 changed files with 14 additions and 21 deletions
|
|
@ -135,7 +135,7 @@ str_addr (const char *str, int *family)
|
|||
NMConnection *
|
||||
nmi_dt_reader_parse (const char *sysfs_dir)
|
||||
{
|
||||
NMConnection *connection;
|
||||
gs_unref_object NMConnection *connection = NULL;
|
||||
gs_free char *base = NULL;
|
||||
gs_free char *bootpath = NULL;
|
||||
gs_strfreev char **tokens = NULL;
|
||||
|
|
@ -144,9 +144,8 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
const char *s_ipaddr = NULL;
|
||||
const char *s_netmask = NULL;
|
||||
const char *s_gateway = NULL;
|
||||
NMIPAddress *ipaddr = NULL;
|
||||
NMIPAddress *netmask = NULL;
|
||||
NMIPAddress *gateway = NULL;
|
||||
nm_auto_unref_ip_address NMIPAddress *ipaddr = NULL;
|
||||
nm_auto_unref_ip_address NMIPAddress *gateway = NULL;
|
||||
const char *duplex = NULL;
|
||||
gs_free char *hwaddr = NULL;
|
||||
gs_free char *local_hwaddr = NULL;
|
||||
|
|
@ -279,10 +278,10 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
connection = nm_simple_connection_new ();
|
||||
|
||||
nm_connection_add_setting (connection,
|
||||
g_object_new (NM_TYPE_SETTING_CONNECTION,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID, "OpenFirmware Connection",
|
||||
NULL));
|
||||
g_object_new (NM_TYPE_SETTING_CONNECTION,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID, "OpenFirmware Connection",
|
||||
NULL));
|
||||
|
||||
s_ip4 = nm_setting_ip4_config_new ();
|
||||
nm_connection_add_setting (connection, s_ip4);
|
||||
|
|
@ -298,6 +297,8 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
bootp = TRUE;
|
||||
|
||||
if (!bootp) {
|
||||
nm_auto_unref_ip_address NMIPAddress *netmask = NULL;
|
||||
|
||||
netmask = dt_get_ipaddr_property (base, "chosen", "netmask-ip", &family);
|
||||
gateway = dt_get_ipaddr_property (base, "chosen", "gateway-ip", &family);
|
||||
if (gateway)
|
||||
|
|
@ -305,9 +306,9 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
ipaddr = dt_get_ipaddr_property (base, "chosen", "client-ip", &family);
|
||||
|
||||
if (family == AF_UNSPEC) {
|
||||
g_warn_if_fail (netmask == NULL);
|
||||
g_warn_if_fail (ipaddr == NULL);
|
||||
g_warn_if_fail (gateway == NULL);
|
||||
nm_assert (netmask == NULL);
|
||||
nm_assert (gateway == NULL);
|
||||
nm_assert (ipaddr == NULL);
|
||||
|
||||
netmask = str_addr (s_netmask, &family);
|
||||
ipaddr = str_addr (s_ipaddr, &family);
|
||||
|
|
@ -326,9 +327,6 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
_LOGW (LOGD_CORE, "Unable to determine the network prefix");
|
||||
else
|
||||
nm_ip_address_set_prefix (ipaddr, prefix);
|
||||
|
||||
if (netmask)
|
||||
nm_ip_address_unref (netmask);
|
||||
}
|
||||
|
||||
if (!ipaddr) {
|
||||
|
|
@ -373,11 +371,6 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
g_object_set (s_ip, NM_SETTING_IP_CONFIG_GATEWAY, s_gateway, NULL);
|
||||
}
|
||||
|
||||
if (ipaddr)
|
||||
nm_ip_address_unref (ipaddr);
|
||||
if (gateway)
|
||||
nm_ip_address_unref (gateway);
|
||||
|
||||
if (duplex || speed || hwaddr || local_hwaddr) {
|
||||
s_wired = nm_setting_wired_new ();
|
||||
nm_connection_add_setting (connection, s_wired);
|
||||
|
|
@ -390,11 +383,11 @@ nmi_dt_reader_parse (const char *sysfs_dir)
|
|||
NULL);
|
||||
}
|
||||
|
||||
if (!nm_connection_normalize (connection, NULL, NULL, &error)) {
|
||||
if (!nm_connection_normalize (connection, NULL, NULL, &error)) {
|
||||
_LOGW (LOGD_CORE, "Generated an invalid connection: %s",
|
||||
error->message);
|
||||
g_clear_pointer (&connection, g_object_unref);
|
||||
}
|
||||
|
||||
return connection;
|
||||
return g_steal_pointer (&connection);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue