@@ -73,9 +73,9 @@ int32_t linux_gpio_get(struct no_os_gpio_desc **desc,
73
73
char path [64 ];
74
74
int ret ;
75
75
int timeout ;
76
- struct gpiochip_info chip_info ;
77
- struct gpio_v2_line_info line_info ;
78
- struct gpio_v2_line_request line_request ;
76
+ struct gpiochip_info chip_info = { 0 } ;
77
+ struct gpio_v2_line_info line_info = { 0 } ;
78
+ struct gpio_v2_line_request line_request = { 0 } ;
79
79
80
80
descriptor = no_os_calloc (1 , sizeof (* descriptor ));
81
81
if (!descriptor )
@@ -101,25 +101,22 @@ int32_t linux_gpio_get(struct no_os_gpio_desc **desc,
101
101
goto close_dir ;
102
102
}
103
103
104
- // Get Chip Info
105
- memset (& chip_info , 0 , sizeof (chip_info ));
104
+ /* Get Chip Info */
106
105
ret = ioctl (linux_desc -> chip_fd , GPIO_GET_CHIPINFO_IOCTL , & chip_info );
107
106
if (ret < 0 ) {
108
107
printf ("%s: Can't get chipinfo\n\r" , __func__ );
109
108
goto close_dir ;
110
109
}
111
110
112
- // Get Line Info
113
- memset (& line_info , 0 , sizeof (line_info ));
111
+ /* Get Line Info */
114
112
line_info .offset = descriptor -> number ;
115
113
ret = ioctl (linux_desc -> chip_fd , GPIO_V2_GET_LINEINFO_IOCTL , & line_info );
116
114
if (ret < 0 ) {
117
115
printf ("%s: Can't get lineinfo\n\r" , __func__ );
118
116
goto close_dir ;
119
117
}
120
118
121
- // Get Line Request
122
- memset (& line_request , 0 , sizeof (line_request ));
119
+ /* Get Line Request */
123
120
line_request .offsets [0 ] = descriptor -> number ;
124
121
line_request .num_lines = 1 ;
125
122
ret = ioctl (linux_desc -> chip_fd , GPIO_V2_GET_LINE_IOCTL , & line_request );
@@ -200,14 +197,13 @@ int32_t linux_gpio_set_value(struct no_os_gpio_desc *desc,
200
197
{
201
198
struct linux_gpio_desc * linux_desc ;
202
199
int ret ;
203
- struct gpio_v2_line_values line_value ;
200
+ struct gpio_v2_line_values line_value = { 0 } ;
204
201
205
202
linux_desc = desc -> extra ;
206
203
207
- // Set Line Value
208
- memset (& line_value , 0 , sizeof (line_value ));
204
+ /* Set Line Value */
209
205
line_value .bits = value ;
210
- line_value .mask = 1 ; // Only set one line (or one GPIO)
206
+ line_value .mask = 1 ; /* Only set one line (or one GPIO) */
211
207
ret = ioctl (linux_desc -> line_fd , GPIO_V2_LINE_SET_VALUES_IOCTL , & line_value );
212
208
if (ret < 0 ) {
213
209
printf ("%s: Can't set line value\n\r" , __func__ );
@@ -230,13 +226,12 @@ int32_t linux_gpio_get_value(struct no_os_gpio_desc *desc,
230
226
{
231
227
struct linux_gpio_desc * linux_desc ;
232
228
int ret ;
233
- struct gpio_v2_line_values line_value ;
229
+ struct gpio_v2_line_values line_value = { 0 } ;
234
230
235
231
linux_desc = desc -> extra ;
236
232
237
- // Get Line Value
238
- memset (& line_value , 0 , sizeof (line_value ));
239
- line_value .mask = 1 ; // Only get one line (or one GPIO)
233
+ /* Get Line Value */
234
+ line_value .mask = 1 ; /* Only get one line (or one GPIO) */
240
235
ret = ioctl (linux_desc -> line_fd , GPIO_V2_LINE_GET_VALUES_IOCTL , & line_value );
241
236
if (ret < 0 ) {
242
237
printf ("%s: Can't get line value\n\r" , __func__ );
@@ -260,12 +255,11 @@ int32_t linux_gpio_direction_input(struct no_os_gpio_desc *desc)
260
255
{
261
256
struct linux_gpio_desc * linux_desc ;
262
257
int ret ;
263
- struct gpio_v2_line_config line_config ;
258
+ struct gpio_v2_line_config line_config = { 0 } ;
264
259
265
260
linux_desc = desc -> extra ;
266
261
267
- // Set Line Config
268
- memset (& line_config , 0 , sizeof (line_config ));
262
+ /* Set Line Config */
269
263
line_config .flags = GPIO_V2_LINE_FLAG_INPUT ;
270
264
ret = ioctl (linux_desc -> line_fd , GPIO_V2_LINE_SET_CONFIG_IOCTL , & line_config );
271
265
if (ret < 0 ) {
@@ -289,12 +283,11 @@ int32_t linux_gpio_direction_output(struct no_os_gpio_desc *desc,
289
283
{
290
284
struct linux_gpio_desc * linux_desc ;
291
285
int ret ;
292
- struct gpio_v2_line_config line_config ;
286
+ struct gpio_v2_line_config line_config = { 0 } ;
293
287
294
288
linux_desc = desc -> extra ;
295
289
296
- // Set Line Config
297
- memset (& line_config , 0 , sizeof (line_config ));
290
+ /* Set Line Config */
298
291
line_config .flags = GPIO_V2_LINE_FLAG_OUTPUT ;
299
292
ret = ioctl (linux_desc -> line_fd , GPIO_V2_LINE_SET_CONFIG_IOCTL , & line_config );
300
293
if (ret < 0 ) {
@@ -320,12 +313,11 @@ int32_t linux_gpio_get_direction(struct no_os_gpio_desc *desc,
320
313
{
321
314
struct linux_gpio_desc * linux_desc ;
322
315
int ret ;
323
- struct gpio_v2_line_info line_info ;
316
+ struct gpio_v2_line_info line_info = { 0 } ;
324
317
325
318
linux_desc = desc -> extra ;
326
319
327
- // Get Line Info
328
- memset (& line_info , 0 , sizeof (line_info ));
320
+ /* Get Line Info */
329
321
line_info .offset = desc -> number ;
330
322
ret = ioctl (linux_desc -> chip_fd , GPIO_V2_GET_LINEINFO_IOCTL , & line_info );
331
323
if (ret < 0 ) {
@@ -334,11 +326,10 @@ int32_t linux_gpio_get_direction(struct no_os_gpio_desc *desc,
334
326
return -1 ;
335
327
}
336
328
337
- if (line_info .flags & GPIO_V2_LINE_FLAG_OUTPUT ) {
329
+ if (line_info .flags & GPIO_V2_LINE_FLAG_OUTPUT )
338
330
* direction = NO_OS_GPIO_OUT ;
339
- } else if (line_info .flags & GPIO_V2_LINE_FLAG_INPUT ) {
331
+ else if (line_info .flags & GPIO_V2_LINE_FLAG_INPUT )
340
332
* direction = NO_OS_GPIO_IN ;
341
- }
342
333
343
334
return 0 ;
344
335
}
0 commit comments