If gpiolib is disabled, we use the inline stubs from gpio/consumer.h instead of regular definitions of GPIO API. The stubs for 'optional' variants of gpiod_get routines return NULL in this case as if the relevant GPIO wasn't found. This is correct so far. Calling other (non-gpio_get) stubs from this header triggers a warning because the GPIO descriptor couldn't have been requested. The warning however is unconditional (WARN_ON(1)) and is emitted even if the passed descriptor pointer is NULL. We don't want to force the users of 'optional' gpio_get to check the returned pointer before calling e.g. gpiod_set_value() so let's only WARN on non-NULL descriptors.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -247,7 +247,7 @@ static inline void gpiod_put(struct gpio_desc *desc) · 246 unmodified lines | |||
| 247 | might_sleep(); | 247 | might_sleep(); |
| 248 | 248 | ||
| 249 | /* GPIO can never have been requested */ | 249 | /* GPIO can never have been requested */ |
| 250 | WARN_ON(1); | 250 | WARN_ON(desc); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | static inline void devm_gpiod_unhinge(struct device *dev, | 253 | static inline void devm_gpiod_unhinge(struct device *dev, |
| @@ -256,7 +256,7 @@ static inline void devm_gpiod_unhinge(struct device *dev, · 2 unmodified lines | |||
| 256 | might_sleep(); | 256 | might_sleep(); |
| 257 | 257 | ||
| 258 | /* GPIO can never have been requested */ | 258 | /* GPIO can never have been requested */ |
| 259 | WARN_ON(1); | 259 | WARN_ON(desc); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | static inline void gpiod_put_array(struct gpio_descs *descs) | 262 | static inline void gpiod_put_array(struct gpio_descs *descs) |
| @@ -264,7 +264,7 @@ static inline void gpiod_put_array(struct gpio_descs *descs) · 1 unmodified line | |||
| 264 | might_sleep(); | 264 | might_sleep(); |
| 265 | 265 | ||
| 266 | /* GPIO can never have been requested */ | 266 | /* GPIO can never have been requested */ |
| 267 | WARN_ON(1); | 267 | WARN_ON(descs); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | static inline struct gpio_desc *__must_check | 270 | static inline struct gpio_desc *__must_check |
| @@ -317,7 +317,7 @@ static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) · 46 unmodified lines | |||
| 317 | might_sleep(); | 317 | might_sleep(); |
| 318 | 318 | ||
| 319 | /* GPIO can never have been requested */ | 319 | /* GPIO can never have been requested */ |
| 320 | WARN_ON(1); | 320 | WARN_ON(desc); |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | static inline void devm_gpiod_put_array(struct device *dev, | 323 | static inline void devm_gpiod_put_array(struct device *dev, |
| @@ -326,32 +326,32 @@ static inline void devm_gpiod_put_array(struct device *dev, · 2 unmodified lines | |||
| 326 | might_sleep(); | 326 | might_sleep(); |
| 327 | 327 | ||
| 328 | /* GPIO can never have been requested */ | 328 | /* GPIO can never have been requested */ |
| 329 | WARN_ON(1); | 329 | WARN_ON(descs); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | 332 | ||
| 333 | static inline int gpiod_get_direction(const struct gpio_desc *desc) | 333 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
| 334 | { | 334 | { |
| 335 | /* GPIO can never have been requested */ | 335 | /* GPIO can never have been requested */ |
| 336 | WARN_ON(1); | 336 | WARN_ON(desc); |
| 337 | return -ENOSYS; | 337 | return -ENOSYS; |
| 338 | } | 338 | } |
| 339 | static inline int gpiod_direction_input(struct gpio_desc *desc) | 339 | static inline int gpiod_direction_input(struct gpio_desc *desc) |
| 340 | { | 340 | { |
| 341 | /* GPIO can never have been requested */ | 341 | /* GPIO can never have been requested */ |
| 342 | WARN_ON(1); | 342 | WARN_ON(desc); |
| 343 | return -ENOSYS; | 343 | return -ENOSYS; |
| 344 | } | 344 | } |
| 345 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) | 345 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) |
| 346 | { | 346 | { |
| 347 | /* GPIO can never have been requested */ | 347 | /* GPIO can never have been requested */ |
| 348 | WARN_ON(1); | 348 | WARN_ON(desc); |
| 349 | return -ENOSYS; | 349 | return -ENOSYS; |
| 350 | } | 350 | } |
| 351 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) | 351 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
| 352 | { | 352 | { |
| 353 | /* GPIO can never have been requested */ | 353 | /* GPIO can never have been requested */ |
| 354 | WARN_ON(1); | 354 | WARN_ON(desc); |
| 355 | return -ENOSYS; | 355 | return -ENOSYS; |
| 356 | } | 356 | } |
| 357 | 357 | ||
| @@ -359,7 +359,7 @@ static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) · 1 unmodified line | |||
| 359 | static inline int gpiod_get_value(const struct gpio_desc *desc) | 359 | static inline int gpiod_get_value(const struct gpio_desc *desc) |
| 360 | { | 360 | { |
| 361 | /* GPIO can never have been requested */ | 361 | /* GPIO can never have been requested */ |
| 362 | WARN_ON(1); | 362 | WARN_ON(desc); |
| 363 | return 0; | 363 | return 0; |
| 364 | } | 364 | } |
| 365 | static inline int gpiod_get_array_value(unsigned int array_size, | 365 | static inline int gpiod_get_array_value(unsigned int array_size, |
| @@ -368,13 +368,13 @@ static inline int gpiod_get_array_value(unsigned int array_size, · 2 unmodified lines | |||
| 368 | unsigned long *value_bitmap) | 368 | unsigned long *value_bitmap) |
| 369 | { | 369 | { |
| 370 | /* GPIO can never have been requested */ | 370 | /* GPIO can never have been requested */ |
| 371 | WARN_ON(1); | 371 | WARN_ON(desc_array); |
| 372 | return 0; | 372 | return 0; |
| 373 | } | 373 | } |
| 374 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) | 374 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
| 375 | { | 375 | { |
| 376 | /* GPIO can never have been requested */ | 376 | /* GPIO can never have been requested */ |
| 377 | WARN_ON(1); | 377 | WARN_ON(desc); |
| 378 | } | 378 | } |
| 379 | static inline int gpiod_set_array_value(unsigned int array_size, | 379 | static inline int gpiod_set_array_value(unsigned int array_size, |
| 380 | struct gpio_desc **desc_array, | 380 | struct gpio_desc **desc_array, |
| @@ -382,13 +382,13 @@ static inline int gpiod_set_array_value(unsigned int array_size, · 1 unmodified line | |||
| 382 | unsigned long *value_bitmap) | 382 | unsigned long *value_bitmap) |
| 383 | { | 383 | { |
| 384 | /* GPIO can never have been requested */ | 384 | /* GPIO can never have been requested */ |
| 385 | WARN_ON(1); | 385 | WARN_ON(desc_array); |
| 386 | return 0; | 386 | return 0; |
| 387 | } | 387 | } |
| 388 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) | 388 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
| 389 | { | 389 | { |
| 390 | /* GPIO can never have been requested */ | 390 | /* GPIO can never have been requested */ |
| 391 | WARN_ON(1); | 391 | WARN_ON(desc); |
| 392 | return 0; | 392 | return 0; |
| 393 | } | 393 | } |
| 394 | static inline int gpiod_get_raw_array_value(unsigned int array_size, | 394 | static inline int gpiod_get_raw_array_value(unsigned int array_size, |
| @@ -397,13 +397,13 @@ static inline int gpiod_get_raw_array_value(unsigned int array_size, · 2 unmodified lines | |||
| 397 | unsigned long *value_bitmap) | 397 | unsigned long *value_bitmap) |
| 398 | { | 398 | { |
| 399 | /* GPIO can never have been requested */ | 399 | /* GPIO can never have been requested */ |
| 400 | WARN_ON(1); | 400 | WARN_ON(desc_array); |
| 401 | return 0; | 401 | return 0; |
| 402 | } | 402 | } |
| 403 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) | 403 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
| 404 | { | 404 | { |
| 405 | /* GPIO can never have been requested */ | 405 | /* GPIO can never have been requested */ |
| 406 | WARN_ON(1); | 406 | WARN_ON(desc); |
| 407 | } | 407 | } |
| 408 | static inline int gpiod_set_raw_array_value(unsigned int array_size, | 408 | static inline int gpiod_set_raw_array_value(unsigned int array_size, |
| 409 | struct gpio_desc **desc_array, | 409 | struct gpio_desc **desc_array, |
| @@ -411,14 +411,14 @@ static inline int gpiod_set_raw_array_value(unsigned int array_size, · 1 unmodified line | |||
| 411 | unsigned long *value_bitmap) | 411 | unsigned long *value_bitmap) |
| 412 | { | 412 | { |
| 413 | /* GPIO can never have been requested */ | 413 | /* GPIO can never have been requested */ |
| 414 | WARN_ON(1); | 414 | WARN_ON(desc_array); |
| 415 | return 0; | 415 | return 0; |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) | 418 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) |
| 419 | { | 419 | { |
| 420 | /* GPIO can never have been requested */ | 420 | /* GPIO can never have been requested */ |
| 421 | WARN_ON(1); | 421 | WARN_ON(desc); |
| 422 | return 0; | 422 | return 0; |
| 423 | } | 423 | } |
| 424 | static inline int gpiod_get_array_value_cansleep(unsigned int array_size, | 424 | static inline int gpiod_get_array_value_cansleep(unsigned int array_size, |
| @@ -427,13 +427,13 @@ static inline int gpiod_get_array_value_cansleep(unsigned int array_size, · 2 unmodified lines | |||
| 427 | unsigned long *value_bitmap) | 427 | unsigned long *value_bitmap) |
| 428 | { | 428 | { |
| 429 | /* GPIO can never have been requested */ | 429 | /* GPIO can never have been requested */ |
| 430 | WARN_ON(1); | 430 | WARN_ON(desc_array); |
| 431 | return 0; | 431 | return 0; |
| 432 | } | 432 | } |
| 433 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) | 433 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
| 434 | { | 434 | { |
| 435 | /* GPIO can never have been requested */ | 435 | /* GPIO can never have been requested */ |
| 436 | WARN_ON(1); | 436 | WARN_ON(desc); |
| 437 | } | 437 | } |
| 438 | static inline int gpiod_set_array_value_cansleep(unsigned int array_size, | 438 | static inline int gpiod_set_array_value_cansleep(unsigned int array_size, |
| 439 | struct gpio_desc **desc_array, | 439 | struct gpio_desc **desc_array, |
| @@ -441,13 +441,13 @@ static inline int gpiod_set_array_value_cansleep(unsigned int array_size, · 1 unmodified line | |||
| 441 | unsigned long *value_bitmap) | 441 | unsigned long *value_bitmap) |
| 442 | { | 442 | { |
| 443 | /* GPIO can never have been requested */ | 443 | /* GPIO can never have been requested */ |
| 444 | WARN_ON(1); | 444 | WARN_ON(desc_array); |
| 445 | return 0; | 445 | return 0; |
| 446 | } | 446 | } |
| 447 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) | 447 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
| 448 | { | 448 | { |
| 449 | /* GPIO can never have been requested */ | 449 | /* GPIO can never have been requested */ |
| 450 | WARN_ON(1); | 450 | WARN_ON(desc); |
| 451 | return 0; | 451 | return 0; |
| 452 | } | 452 | } |
| 453 | static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, | 453 | static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
| @@ -456,14 +456,14 @@ static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, · 2 unmodified lines | |||
| 456 | unsigned long *value_bitmap) | 456 | unsigned long *value_bitmap) |
| 457 | { | 457 | { |
| 458 | /* GPIO can never have been requested */ | 458 | /* GPIO can never have been requested */ |
| 459 | WARN_ON(1); | 459 | WARN_ON(desc_array); |
| 460 | return 0; | 460 | return 0; |
| 461 | } | 461 | } |
| 462 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, | 462 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
| 463 | int value) | 463 | int value) |
| 464 | { | 464 | { |
| 465 | /* GPIO can never have been requested */ | 465 | /* GPIO can never have been requested */ |
| 466 | WARN_ON(1); | 466 | WARN_ON(desc); |
| 467 | } | 467 | } |
| 468 | static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, | 468 | static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
| 469 | struct gpio_desc **desc_array, | 469 | struct gpio_desc **desc_array, |
| @@ -471,41 +471,41 @@ static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, · 1 unmodified line | |||
| 471 | unsigned long *value_bitmap) | 471 | unsigned long *value_bitmap) |
| 472 | { | 472 | { |
| 473 | /* GPIO can never have been requested */ | 473 | /* GPIO can never have been requested */ |
| 474 | WARN_ON(1); | 474 | WARN_ON(desc_array); |
| 475 | return 0; | 475 | return 0; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) | 478 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) |
| 479 | { | 479 | { |
| 480 | /* GPIO can never have been requested */ | 480 | /* GPIO can never have been requested */ |
| 481 | WARN_ON(1); | 481 | WARN_ON(desc); |
| 482 | return -ENOSYS; | 482 | return -ENOSYS; |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) | 485 | static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) |
| 486 | { | 486 | { |
| 487 | /* GPIO can never have been requested */ | 487 | /* GPIO can never have been requested */ |
| 488 | WARN_ON(1); | 488 | WARN_ON(desc); |
| 489 | return -ENOSYS; | 489 | return -ENOSYS; |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) | 492 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
| 493 | { | 493 | { |
| 494 | /* GPIO can never have been requested */ | 494 | /* GPIO can never have been requested */ |
| 495 | WARN_ON(1); | 495 | WARN_ON(desc); |
| 496 | return 0; | 496 | return 0; |
| 497 | } | 497 | } |
| 498 | static inline int gpiod_cansleep(const struct gpio_desc *desc) | 498 | static inline int gpiod_cansleep(const struct gpio_desc *desc) |
| 499 | { | 499 | { |
| 500 | /* GPIO can never have been requested */ | 500 | /* GPIO can never have been requested */ |
| 501 | WARN_ON(1); | 501 | WARN_ON(desc); |
| 502 | return 0; | 502 | return 0; |
| 503 | } | 503 | } |
| 504 | 504 | ||
| 505 | static inline int gpiod_to_irq(const struct gpio_desc *desc) | 505 | static inline int gpiod_to_irq(const struct gpio_desc *desc) |
| 506 | { | 506 | { |
| 507 | /* GPIO can never have been requested */ | 507 | /* GPIO can never have been requested */ |
| 508 | WARN_ON(1); | 508 | WARN_ON(desc); |
| 509 | return -EINVAL; | 509 | return -EINVAL; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| @@ -513,7 +513,7 @@ static inline int gpiod_set_consumer_name(struct gpio_desc *desc, · 1 unmodified line | |||
| 513 | const char *name) | 513 | const char *name) |
| 514 | { | 514 | { |
| 515 | /* GPIO can never have been requested */ | 515 | /* GPIO can never have been requested */ |
| 516 | WARN_ON(1); | 516 | WARN_ON(desc); |
| 517 | return -EINVAL; | 517 | return -EINVAL; |
| 518 | } | 518 | } |
| 519 | 519 | ||
| @@ -525,7 +525,7 @@ static inline struct gpio_desc *gpio_to_desc(unsigned gpio) · 5 unmodified lines | |||
| 525 | static inline int desc_to_gpio(const struct gpio_desc *desc) | 525 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
| 526 | { | 526 | { |
| 527 | /* GPIO can never have been requested */ | 527 | /* GPIO can never have been requested */ |
| 528 | WARN_ON(1); | 528 | WARN_ON(desc); |
| 529 | return -EINVAL; | 529 | return -EINVAL; |
| 530 | } | 530 | } |
| 531 | 531 | ||