Re: [PATCH 1/3] libibumad: Support arbitrary number of IB devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 8/13/2019 7:39 PM, Ira Weiny wrote:
> On Sun, Aug 11, 2019 at 04:29:20PM +0000, Haim Boozaglo wrote:
>> From: Vladimir Koushnir <vladimirk@xxxxxxxxxxxx>
>>
>> Added new function returning a list of available InfiniBand device names.
>> The returned list is not limited to 32 devices.
>>
>> Signed-off-by: Vladimir Koushnir <vladimirk@xxxxxxxxxxxx>
>> Signed-off-by: Haim Boozaglo <haimbo@xxxxxxxxxxxx>
>> ---
> 
> [snip]
> 
>> diff --git a/libibumad/umad.c b/libibumad/umad.c
>> index 5f8656e..9d0303b 100644
>> --- a/libibumad/umad.c
>> +++ b/libibumad/umad.c
>> @@ -1123,3 +1123,44 @@ void umad_dump(void *umad)
>>   	       mad->agent_id, mad->status, mad->timeout_ms);
>>   	umad_addr_dump(&mad->addr);
>>   }
>> +
>> +int umad_get_ca_namelist(char **cas)
>> +{
>> +	struct dirent **namelist;
>> +	int n, i, j = 0;
>> +
>> +	n = scandir(SYS_INFINIBAND, &namelist, NULL, alphasort);
>> +
>> +	if (n > 0) {
>> +		*cas = (char *) calloc(1, n * sizeof(char) * UMAD_CA_NAME_LEN);
>> +		for (i = 0; i < n; i++) {
>> +			if (*cas && strcmp(namelist[i]->d_name, ".") &&
>> +			    strcmp(namelist[i]->d_name, "..")) {
>> +				if (is_ib_type(namelist[i]->d_name)) {
>> +					strncpy(*cas + j * UMAD_CA_NAME_LEN,
>> +						namelist[i]->d_name,
>> +						UMAD_CA_NAME_LEN);
>> +					j++;
>> +				}
> 
> This all seems overly complicated to avoid allocating the strings separate from
> the pointer array.  Why not just allocate the pointer array and strdup() the
> names into the array?  And then make unamd_free_ca_namelist() do some work?
> 
> Ira

Hi Ira,
Thats what I am going to do and fix (to use strdup),

Thanks,
Haim.

> 
>> +			}
>> +			free(namelist[i]);
>> +		}
>> +		DEBUG("return %d cas", j);
>> +	} else {
>> +		/* Is this still needed ? */
>> +		if ((*cas = calloc(1, UMAD_CA_NAME_LEN * sizeof(char)))) {
>> +			strncpy(*cas, def_ca_name, UMAD_CA_NAME_LEN);
>> +			DEBUG("return 1 ca");
>> +			j = 1;
>> +		}
>> +	}
>> +	if (n >= 0)
>> +		free(namelist);
>> +
>> +	return j;
>> +}
>> +
>> +void umad_free_ca_namelist(char *cas)
>> +{
>> +	free(cas);
>> +}
>> diff --git a/libibumad/umad.h b/libibumad/umad.h
>> index 3cc551f..70bc213 100644
>> --- a/libibumad/umad.h
>> +++ b/libibumad/umad.h
>> @@ -208,6 +208,8 @@ int umad_register(int portid, int mgmt_class, int mgmt_version,
>>   int umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version,
>>   		      uint8_t oui[3], long method_mask[16 / sizeof(long)]);
>>   int umad_unregister(int portid, int agentid);
>> +int umad_get_ca_namelist(char **cas);
>> +void umad_free_ca_namelist(char *cas);
>>   
>>   enum {
>>   	UMAD_USER_RMPP = (1 << 0)
>> -- 
>> 1.8.3.1
>>




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux