samples, tests, boards: Switch main return type from void to int

As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2023-02-07 21:00:59 -08:00 committed by Stephanos Ioannidis
commit 0b90fd5adf
447 changed files with 1617 additions and 1231 deletions

View file

@ -19,24 +19,25 @@
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
void main(void)
int main(void)
{
int ret;
if (!gpio_is_ready_dt(&led)) {
return;
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return;
return 0;
}
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return;
return 0;
}
k_msleep(SLEEP_TIME_MS);
}
return 0;
}

View file

@ -19,7 +19,7 @@ static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
#define MIN_PERIOD PWM_SEC(1U) / 128U
#define MAX_PERIOD PWM_SEC(1U)
void main(void)
int main(void)
{
uint32_t max_period;
uint32_t period;
@ -31,7 +31,7 @@ void main(void)
if (!device_is_ready(pwm_led0.dev)) {
printk("Error: PWM device %s is not ready\n",
pwm_led0.dev->name);
return;
return 0;
}
/*
@ -49,7 +49,7 @@ void main(void)
printk("Error: PWM device "
"does not support a period at least %lu\n",
4U * MIN_PERIOD);
return;
return 0;
}
}
@ -61,7 +61,7 @@ void main(void)
ret = pwm_set_dt(&pwm_led0, period, period / 2U);
if (ret) {
printk("Error %d: failed to set pulse width\n", ret);
return;
return 0;
}
period = dir ? (period * 2U) : (period / 2U);
@ -75,4 +75,5 @@ void main(void)
k_sleep(K_SECONDS(4U));
}
return 0;
}

View file

@ -38,21 +38,21 @@ void button_pressed(const struct device *dev, struct gpio_callback *cb,
printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
}
void main(void)
int main(void)
{
int ret;
if (!gpio_is_ready_dt(&button)) {
printk("Error: button device %s is not ready\n",
button.port->name);
return;
return 0;
}
ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
if (ret != 0) {
printk("Error %d: failed to configure %s pin %d\n",
ret, button.port->name, button.pin);
return;
return 0;
}
ret = gpio_pin_interrupt_configure_dt(&button,
@ -60,7 +60,7 @@ void main(void)
if (ret != 0) {
printk("Error %d: failed to configure interrupt on %s pin %d\n",
ret, button.port->name, button.pin);
return;
return 0;
}
gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
@ -95,4 +95,5 @@ void main(void)
k_msleep(SLEEP_TIME_MS);
}
}
return 0;
}

View file

@ -17,13 +17,13 @@
static const struct gpio_dt_spec load_switch =
GPIO_DT_SPEC_GET_OR(DT_NODELABEL(load_switch), gpios, {0});
void main(void)
int main(void)
{
int err;
if (!gpio_is_ready_dt(&load_switch)) {
printf("The load switch pin GPIO port is not ready.\n");
return;
return 0;
}
printf("Initializing pin with inactive level.\n");
@ -31,7 +31,7 @@ void main(void)
err = gpio_pin_configure_dt(&load_switch, GPIO_OUTPUT_INACTIVE);
if (err != 0) {
printf("Configuring GPIO pin failed: %d\n", err);
return;
return 0;
}
printf("Waiting one second.\n");
@ -44,4 +44,5 @@ void main(void)
if (err != 0) {
printf("Setting GPIO pin level failed: %d\n", err);
}
return 0;
}

View file

@ -19,7 +19,7 @@ static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
#define NUM_STEPS 50U
#define SLEEP_MSEC 25U
void main(void)
int main(void)
{
uint32_t pulse_width = 0U;
uint32_t step = pwm_led0.period / NUM_STEPS;
@ -31,14 +31,14 @@ void main(void)
if (!device_is_ready(pwm_led0.dev)) {
printk("Error: PWM device %s is not ready\n",
pwm_led0.dev->name);
return;
return 0;
}
while (1) {
ret = pwm_set_pulse_dt(&pwm_led0, pulse_width);
if (ret) {
printk("Error %d: failed to set pulse width\n", ret);
return;
return 0;
}
if (dir) {
@ -58,4 +58,5 @@ void main(void)
k_sleep(K_MSEC(SLEEP_MSEC));
}
return 0;
}

View file

@ -26,7 +26,7 @@ struct _stats {
static void print_stats(const struct _stats *stats);
void main(void)
int main(void)
{
size_t i;
int ires;
@ -89,9 +89,7 @@ out:
LOG_INF("success");
if (IS_ENABLED(CONFIG_ARCH_POSIX)) {
exit(0);
}
return 0;
}
static void print_stats(const struct _stats *stats)

View file

@ -6,6 +6,7 @@
#include <zephyr/kernel.h>
void main(void)
int main(void)
{
return 0;
}

View file

@ -22,7 +22,7 @@ static const struct pwm_dt_spec blue_pwm_led =
#define STEP_SIZE PWM_USEC(2000)
void main(void)
int main(void)
{
uint32_t pulse_red, pulse_green, pulse_blue; /* pulse widths */
int ret;
@ -33,7 +33,7 @@ void main(void)
!device_is_ready(green_pwm_led.dev) ||
!device_is_ready(blue_pwm_led.dev)) {
printk("Error: one or more PWM devices not ready\n");
return;
return 0;
}
while (1) {
@ -42,7 +42,7 @@ void main(void)
ret = pwm_set_pulse_dt(&red_pwm_led, pulse_red);
if (ret != 0) {
printk("Error %d: red write failed\n", ret);
return;
return 0;
}
for (pulse_green = 0U;
@ -53,7 +53,7 @@ void main(void)
if (ret != 0) {
printk("Error %d: green write failed\n",
ret);
return;
return 0;
}
for (pulse_blue = 0U;
@ -65,11 +65,12 @@ void main(void)
printk("Error %d: "
"blue write failed\n",
ret);
return;
return 0;
}
k_sleep(K_SECONDS(1));
}
}
}
}
return 0;
}

View file

@ -24,7 +24,7 @@ enum direction {
UP,
};
void main(void)
int main(void)
{
uint32_t pulse_width = min_pulse;
enum direction dir = UP;
@ -34,14 +34,14 @@ void main(void)
if (!device_is_ready(servo.dev)) {
printk("Error: PWM device %s is not ready\n", servo.dev->name);
return;
return 0;
}
while (1) {
ret = pwm_set_pulse_dt(&servo, pulse_width);
if (ret < 0) {
printk("Error %d: failed to set pulse width\n", ret);
return;
return 0;
}
if (dir == DOWN) {
@ -62,4 +62,5 @@ void main(void)
k_sleep(K_SECONDS(1));
}
return 0;
}

View file

@ -14,7 +14,7 @@ static struct sys_heap heap;
void print_sys_memory_stats(void);
void main(void)
int main(void)
{
void *p;
@ -31,6 +31,7 @@ void main(void)
sys_heap_free(&heap, p);
print_sys_memory_stats();
return 0;
}
void print_sys_memory_stats(void)