diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2017-12-20 19:27:04 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2017-12-21 17:09:51 -0500 |
commit | a746a232184822a649d36275edbd031c6550324d (patch) | |
tree | a97aef387fc6821e674b4dfc11f8ecfefe52b9aa | |
parent | 1696784eb7b52b13b62d160c028ef2c2c981d4f2 (diff) |
gpio: reduce descriptor validation code size
While we do need macros to be able to return from the "calling"
function, we can still factor the checks done by the VALIDATE_DESC*
macros into a real helper function. This reduces the backslashtitis,
avoids duplicating the logic in the two macros and saves about 1K of
generated code:
$ scripts/bloat-o-meter drivers/gpio/gpiolib.o.{0,1}
add/remove: 1/0 grow/shrink: 0/15 up/down: 104/-1281 (-1177)
Function old new delta
validate_desc - 104 +104
gpiod_set_value 192 135 -57
gpiod_set_raw_value 125 67 -58
gpiod_direction_output 412 351 -61
gpiod_set_value_cansleep 150 70 -80
gpiod_set_raw_value_cansleep 132 52 -80
gpiod_get_raw_value 139 54 -85
gpiod_set_debounce 226 140 -86
gpiod_direction_output_raw 124 38 -86
gpiod_get_value 161 74 -87
gpiod_cansleep 126 39 -87
gpiod_get_raw_value_cansleep 130 39 -91
gpiod_get_value_cansleep 152 59 -93
gpiod_is_active_low 128 33 -95
gpiod_request 299 184 -115
gpiod_direction_input 386 266 -120
Total: Before=25460, After=24283, chg -4.62%
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpiolib.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 45c20307630a..fb1441315bc3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -2158,40 +2158,37 @@ done: | |||
2158 | * macro to avoid endless duplication. If the desc is NULL it is an | 2158 | * macro to avoid endless duplication. If the desc is NULL it is an |
2159 | * optional GPIO and calls should just bail out. | 2159 | * optional GPIO and calls should just bail out. |
2160 | */ | 2160 | */ |
2161 | static int validate_desc(const struct gpio_desc *desc, const char *func) | ||
2162 | { | ||
2163 | if (!desc) | ||
2164 | return 0; | ||
2165 | if (IS_ERR(desc)) { | ||
2166 | pr_warn("%s: invalid GPIO (errorpointer)\n", func); | ||
2167 | return PTR_ERR(desc); | ||
2168 | } | ||
2169 | if (!desc->gdev) { | ||
2170 | pr_warn("%s: invalid GPIO (no device)\n", func); | ||
2171 | return -EINVAL; | ||
2172 | } | ||
2173 | if (!desc->gdev->chip) { | ||
2174 | dev_warn(&desc->gdev->dev, | ||
2175 | "%s: backing chip is gone\n", func); | ||
2176 | return 0; | ||
2177 | } | ||
2178 | return 1; | ||
2179 | } | ||
2180 | |||
2161 | #define VALIDATE_DESC(desc) do { \ | 2181 | #define VALIDATE_DESC(desc) do { \ |
2162 | if (!desc) \ | 2182 | int __valid = validate_desc(desc, __func__); \ |
2163 | return 0; \ | 2183 | if (__valid <= 0) \ |
2164 | if (IS_ERR(desc)) { \ | 2184 | return __valid; \ |
2165 | pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \ | 2185 | } while (0) |
2166 | return PTR_ERR(desc); \ | ||
2167 | } \ | ||
2168 | if (!desc->gdev) { \ | ||
2169 | pr_warn("%s: invalid GPIO (no device)\n", __func__); \ | ||
2170 | return -EINVAL; \ | ||
2171 | } \ | ||
2172 | if ( !desc->gdev->chip ) { \ | ||
2173 | dev_warn(&desc->gdev->dev, \ | ||
2174 | "%s: backing chip is gone\n", __func__); \ | ||
2175 | return 0; \ | ||
2176 | } } while (0) | ||
2177 | 2186 | ||
2178 | #define VALIDATE_DESC_VOID(desc) do { \ | 2187 | #define VALIDATE_DESC_VOID(desc) do { \ |
2179 | if (!desc) \ | 2188 | int __valid = validate_desc(desc, __func__); \ |
2180 | return; \ | 2189 | if (__valid <= 0) \ |
2181 | if (IS_ERR(desc)) { \ | ||
2182 | pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \ | ||
2183 | return; \ | 2190 | return; \ |
2184 | } \ | 2191 | } while (0) |
2185 | if (!desc->gdev) { \ | ||
2186 | pr_warn("%s: invalid GPIO (no device)\n", __func__); \ | ||
2187 | return; \ | ||
2188 | } \ | ||
2189 | if (!desc->gdev->chip) { \ | ||
2190 | dev_warn(&desc->gdev->dev, \ | ||
2191 | "%s: backing chip is gone\n", __func__); \ | ||
2192 | return; \ | ||
2193 | } } while (0) | ||
2194 | |||
2195 | 2192 | ||
2196 | int gpiod_request(struct gpio_desc *desc, const char *label) | 2193 | int gpiod_request(struct gpio_desc *desc, const char *label) |
2197 | { | 2194 | { |