Re: [Linuxptp-devel] [PATCH RFC 27/30] pmc: Use the proper create/destroy API for network interfaces.

2020-02-18 Thread Jacob Keller
On 2/11/2020 6:04 AM, Richard Cochran wrote:
> Signed-off-by: Richard Cochran 

Reviewed-by: Jacob Keller 

> ---
>  pmc_common.c | 19 ---
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/pmc_common.c b/pmc_common.c
> index 41181fb..3aab4b9 100644
> --- a/pmc_common.c
> +++ b/pmc_common.c
> @@ -313,6 +313,7 @@ struct pmc {
>   struct PortIdentity target;
>  
>   struct transport *transport;
> + struct interface *iface;
>   struct fdarray fdarray;
>   int zero_length_gets;
>  };
> @@ -322,11 +323,8 @@ struct pmc *pmc_create(struct config *cfg, enum 
> transport_type transport_type,
>  UInteger8 domain_number, UInteger8 transport_specific,
>  int zero_datalen)
>  {
> - struct interface iface;
>   struct pmc *pmc;
>  
> - memset(, 0, sizeof(iface));
> -
>   pmc = calloc(1, sizeof *pmc);
>   if (!pmc)
>   return NULL;
> @@ -350,18 +348,24 @@ struct pmc *pmc_create(struct config *cfg, enum 
> transport_type transport_type,
>   goto failed;
>   }
>  
> - interface_set_name(, iface_name);
> - interface_ensure_tslabel();
> + pmc->iface = interface_create(iface_name);
> + if (!pmc->iface) {
> + pr_err("failed to create interface");
> + goto failed;
> + }
> + interface_ensure_tslabel(pmc->iface);
>  
> - if (transport_open(pmc->transport, ,
> + if (transport_open(pmc->transport, pmc->iface,
>  >fdarray, TS_SOFTWARE)) {
>   pr_err("failed to open transport");
> - goto failed;
> + goto no_trans_open;
>   }
>   pmc->zero_length_gets = zero_datalen ? 1 : 0;
>  
>   return pmc;
>  
> +no_trans_open:
> + interface_destroy(pmc->iface);
>  failed:
>   if (pmc->transport)
>   transport_destroy(pmc->transport);
> @@ -372,6 +376,7 @@ failed:
>  void pmc_destroy(struct pmc *pmc)
>  {
>   transport_close(pmc->transport, >fdarray);
> + interface_destroy(pmc->iface);
>   transport_destroy(pmc->transport);
>   free(pmc);
>  }
> 


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 27/30] pmc: Use the proper create/destroy API for network interfaces.

2020-02-11 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 pmc_common.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/pmc_common.c b/pmc_common.c
index 41181fb..3aab4b9 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -313,6 +313,7 @@ struct pmc {
struct PortIdentity target;
 
struct transport *transport;
+   struct interface *iface;
struct fdarray fdarray;
int zero_length_gets;
 };
@@ -322,11 +323,8 @@ struct pmc *pmc_create(struct config *cfg, enum 
transport_type transport_type,
   UInteger8 domain_number, UInteger8 transport_specific,
   int zero_datalen)
 {
-   struct interface iface;
struct pmc *pmc;
 
-   memset(, 0, sizeof(iface));
-
pmc = calloc(1, sizeof *pmc);
if (!pmc)
return NULL;
@@ -350,18 +348,24 @@ struct pmc *pmc_create(struct config *cfg, enum 
transport_type transport_type,
goto failed;
}
 
-   interface_set_name(, iface_name);
-   interface_ensure_tslabel();
+   pmc->iface = interface_create(iface_name);
+   if (!pmc->iface) {
+   pr_err("failed to create interface");
+   goto failed;
+   }
+   interface_ensure_tslabel(pmc->iface);
 
-   if (transport_open(pmc->transport, ,
+   if (transport_open(pmc->transport, pmc->iface,
   >fdarray, TS_SOFTWARE)) {
pr_err("failed to open transport");
-   goto failed;
+   goto no_trans_open;
}
pmc->zero_length_gets = zero_datalen ? 1 : 0;
 
return pmc;
 
+no_trans_open:
+   interface_destroy(pmc->iface);
 failed:
if (pmc->transport)
transport_destroy(pmc->transport);
@@ -372,6 +376,7 @@ failed:
 void pmc_destroy(struct pmc *pmc)
 {
transport_close(pmc->transport, >fdarray);
+   interface_destroy(pmc->iface);
transport_destroy(pmc->transport);
free(pmc);
 }
-- 
2.20.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel