Re: [Linuxptp-devel] [PATCH RFC 24/30] interface: Introduce methods to create and destroy instances.

2020-03-05 Thread Jacob Keller
On 3/4/2020 9:19 AM, Richard Cochran wrote:
> On Tue, Feb 18, 2020 at 01:25:00PM -0800, Jacob Keller wrote:
>>
>> I still think it would be good to have the functions guarantee the NULL
>> by manually assigning or using one of the string copy implementations
>> that will guarantee it. That way they don't have to rely on this assumption.
> 
> In the final version, we have,
> 
>   char name[MAX_IFNAME_SIZE + 1]; 
>   
>  
>   char ts_label[MAX_IFNAME_SIZE + 1]; 
>   
>  
>   strncpy(iface->name, name, MAX_IFNAME_SIZE);
>   
>  
>   memcpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE);  
>
>   strncpy(iface->ts_label, label, MAX_IFNAME_SIZE);   
>   
>  
> 
> so I think it is clear enough.  The use of MAX_IFNAME_SIZE is key.
> 
> Thanks,
> Richard
> 

Sure. It's not a big deal to me either way.


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


Re: [Linuxptp-devel] [PATCH RFC 24/30] interface: Introduce methods to create and destroy instances.

2020-03-04 Thread Richard Cochran
On Tue, Feb 18, 2020 at 01:25:00PM -0800, Jacob Keller wrote:
> 
> I still think it would be good to have the functions guarantee the NULL
> by manually assigning or using one of the string copy implementations
> that will guarantee it. That way they don't have to rely on this assumption.

In the final version, we have,

char name[MAX_IFNAME_SIZE + 1]; 
   
char ts_label[MAX_IFNAME_SIZE + 1]; 
   
strncpy(iface->name, name, MAX_IFNAME_SIZE);
   
memcpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE);  
   
strncpy(iface->ts_label, label, MAX_IFNAME_SIZE);   
   

so I think it is clear enough.  The use of MAX_IFNAME_SIZE is key.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH RFC 24/30] interface: Introduce methods to create and destroy instances.

2020-02-18 Thread Jacob Keller
On 2/11/2020 6:04 AM, Richard Cochran wrote:
> In order to eventually hide the implementation details of the interface,
> users will need to be able to create and destroy instances thereof.  This
> patch adds the needed methods.
> 
> Signed-off-by: Richard Cochran 

Reviewed-by: Jacob Keller 

> ---
>  interface.c | 19 +++
>  interface.h | 13 +
>  2 files changed, 32 insertions(+)
> 
> diff --git a/interface.c b/interface.c
> index 74a2512..63ed7e4 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -4,8 +4,27 @@
>   * @note Copyright (C) 2020 Richard Cochran 
>   * @note SPDX-License-Identifier: GPL-2.0+
>   */
> +#include 
>  #include "interface.h"
>  
> +struct interface *interface_create(const char *name)
> +{
> + struct interface *iface;
> +
> + iface = calloc(1, sizeof(struct interface));

Good, calloc guarantees that the interface structure is always zero'd.
That means we don't actually need to worry about interfaces where the
MAS_IFNAME_SIZE arrays end on non-zero. Ok.

I still think it would be good to have the functions guarantee the NULL
by manually assigning or using one of the string copy implementations
that will guarantee it. That way they don't have to rely on this assumption.

> + if (!iface) {
> + return NULL;
> + }
> + interface_set_name(iface, name);
> +
> + return iface;
> +}
> +
> +void interface_destroy(struct interface *iface)
> +{
> + free(iface);
> +}
> +
>  void interface_ensure_tslabel(struct interface *iface)
>  {
>   if (!iface->ts_label[0]) {
> diff --git a/interface.h b/interface.h
> index 32eec7b..b61f4d6 100644
> --- a/interface.h
> +++ b/interface.h
> @@ -25,6 +25,19 @@ struct interface {
>   struct sk_ts_info ts_info;
>  };
>  
> +/**
> + * Creates an instance of an interface.
> + * @param name  The device which indentifies this interface.
> + * @return  A pointer to an interface instance on success, NULL 
> otherwise.
> + */
> +struct interface *interface_create(const char *name);
> +
> +/**
> + * Destroys an instance of an interface.
> + * @param iface  A pointer obtained via interface_create().
> + */
> +void interface_destroy(struct interface *iface);
> +
>  /**
>   * Ensures that an interface has a proper time stamping label.
>   * @param iface  The interface of interest.
> 


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