From 27612798395861c5a3a6b9e1e2de6e39b562eaf4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 6 Dec 2019 23:36:33 -0600 Subject: [PATCH] drivers/bch, pipes, timers: Run drivers through tools/nxstyle, correcting as many complaints as possible. --- drivers/bch/bchdev_driver.c | 25 +++++++++++++------------ drivers/bch/bchdev_unregister.c | 3 +-- drivers/bch/bchlib_cache.c | 2 ++ drivers/pipes/pipe_common.c | 13 ++++++------- drivers/timers/arch_timer.c | 4 +++- drivers/timers/cs2100-cp.c | 33 +++++++++++++++++---------------- drivers/timers/ds3231.c | 29 ++++++++++++++++++----------- drivers/timers/mcp794xx.c | 26 +++++++++++++++----------- drivers/timers/pcf85263.c | 29 ++++++++++++++++++----------- drivers/timers/pwm.c | 3 ++- 10 files changed, 95 insertions(+), 72 deletions(-) diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 8593899527..cb60d3cef9 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -194,22 +194,22 @@ static int bch_close(FAR struct file *filep) if (bch->refs == 0 && bch->unlinked) { - /* Tear the driver down now. */ + /* Tear the driver down now. */ - ret = bchlib_teardown((FAR void *)bch); + ret = bchlib_teardown((FAR void *)bch); - /* bchlib_teardown() would only fail if there are outstanding - * references on the device. Since we know that is not true, it - * should not fail at all. - */ + /* bchlib_teardown() would only fail if there are outstanding + * references on the device. Since we know that is not true, it + * should not fail at all. + */ - DEBUGASSERT(ret >= 0); - if (ret >= 0) - { - /* Return without releasing the stale semaphore */ + DEBUGASSERT(ret >= 0); + if (ret >= 0) + { + /* Return without releasing the stale semaphore */ - return OK; - } + return OK; + } } } @@ -250,6 +250,7 @@ static off_t bch_seek(FAR struct file *filep, off_t offset, int whence) break; default: + /* Return EINVAL if the whence argument is invalid */ bchlib_semgive(bch); diff --git a/drivers/bch/bchdev_unregister.c b/drivers/bch/bchdev_unregister.c index a18a2264b7..05e2123134 100644 --- a/drivers/bch/bchdev_unregister.c +++ b/drivers/bch/bchdev_unregister.c @@ -65,8 +65,7 @@ * * Description: * Unregister character driver access to a block device that was created - / -* by a previous call to bchdev_register(). + * by a previous call to bchdev_register(). * ****************************************************************************/ diff --git a/drivers/bch/bchlib_cache.c b/drivers/bch/bchlib_cache.c index 82090981cd..7999605836 100644 --- a/drivers/bch/bchlib_cache.c +++ b/drivers/bch/bchlib_cache.c @@ -189,11 +189,13 @@ int bchlib_readsector(FAR struct bchlib_s *bch, size_t sector) { ferr("Read failed: %d\n"); } + bch->sector = sector; #if defined(CONFIG_BCH_ENCRYPTION) bch_cypher(bch, CYPHER_DECRYPT); #endif } + return (int)ret; } diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 9fc5da07f0..d5250be11a 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -177,12 +177,12 @@ FAR struct pipe_dev_s *pipecommon_allocdev(size_t bufsize) nxsem_init(&dev->d_rdsem, 0, 0); nxsem_init(&dev->d_wrsem, 0, 0); - /* The read/write wait semaphores are used for signaling and, hence, - * should not have priority inheritance enabled. - */ + /* The read/write wait semaphores are used for signaling and, hence, + * should not have priority inheritance enabled. + */ - nxsem_setprotocol(&dev->d_rdsem, SEM_PRIO_NONE); - nxsem_setprotocol(&dev->d_wrsem, SEM_PRIO_NONE); + nxsem_setprotocol(&dev->d_rdsem, SEM_PRIO_NONE); + nxsem_setprotocol(&dev->d_wrsem, SEM_PRIO_NONE); dev->d_bufsize = bufsize; } @@ -241,7 +241,6 @@ int pipecommon_open(FAR struct file *filep) } } - /* If opened for writing, increment the count of writers on the pipe instance */ if ((filep->f_oflags & O_WROK) != 0) @@ -790,7 +789,7 @@ int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (dev == NULL) { - return -EBADF; + return -EBADF; } #endif diff --git a/drivers/timers/arch_timer.c b/drivers/timers/arch_timer.c index bc9d8b138e..774d593003 100644 --- a/drivers/timers/arch_timer.c +++ b/drivers/timers/arch_timer.c @@ -320,9 +320,11 @@ void up_timer_getmask(FAR uint64_t *mask) { break; } + *mask = next; - } + } } + #elif defined(CONFIG_SCHED_TICKLESS) int up_timer_gettime(FAR struct timespec *ts) { diff --git a/drivers/timers/cs2100-cp.c b/drivers/timers/cs2100-cp.c index c00e01a4f6..d4791082bc 100644 --- a/drivers/timers/cs2100-cp.c +++ b/drivers/timers/cs2100-cp.c @@ -466,38 +466,38 @@ static int cs2100_ratio(FAR const struct cs2100_config_s *config) * a high-precision (b20) value. */ - if (rudb24 < (1ull << (32+7))) + if (rudb24 < (1ull << (32 + 7))) { highmul = false; /* Brute force! */ - if (rudb24 >= (1ull << (32+6))) + if (rudb24 >= (1ull << (32 + 6))) { rud = (uint32_t)rudb24 >> 7; /* RUD = RUDb20 / 8 */ rmod = 3; /* Reff = 8 * RUD */ } - else if (rudb24 >= (1ull << (32+5))) + else if (rudb24 >= (1ull << (32 + 5))) { rud = (uint32_t)rudb24 >> 6; /* RUD = RUDb20 / 4 */ rmod = 3; /* Reff = 4 * RUD */ } - else if (rudb24 >= (1ull << (32+4))) + else if (rudb24 >= (1ull << (32 + 4))) { rud = (uint32_t)rudb24 >> 5; /* RUD = RUDb20 / 2 */ rmod = 1; /* Reff = 2 * RUD */ } - else if (rudb24 >= (1ull << (32+3))) + else if (rudb24 >= (1ull << (32 + 3))) { rud = (uint32_t)rudb24 >> 4; /* RUD = RUDb20 */ rmod = 0; /* Reff = RUD */ } - else if (rudb24 >= (1ull << (32+2))) + else if (rudb24 >= (1ull << (32 + 2))) { rud = (uint32_t)rudb24 >> 3; /* RUD -> 2*RUDb20 */ rmod = 4; /* Reff = RUD / 2 */ } - else if (rudb24 >= (1ull << (32+1))) + else if (rudb24 >= (1ull << (32 + 1))) { rud = (uint32_t)rudb24 >> 2; /* RUD -> 4*RUDb20 */ rmod = 5; /* Reff = RUD / 4 */ @@ -518,31 +518,31 @@ static int cs2100_ratio(FAR const struct cs2100_config_s *config) * a high-multiplication (b12) value. */ - else if (rudb24 < (1ull << (32+12))) + else if (rudb24 < (1ull << (32 + 12))) { highmul = true; - if (rudb24 >= (1ull << (32+11))) + if (rudb24 >= (1ull << (32 + 11))) { rud = (uint32_t)rudb24 >> 12; /* RUD = RUDb12 */ rmod = 0; /* Reff = RUD */ } - else if (rudb24 >= (1ull << (32+10))) + else if (rudb24 >= (1ull << (32 + 10))) { rud = (uint32_t)rudb24 >> 11; /* RUD = 2*RUDb12 */ rmod = 4; /* Reff = RUD / 2 */ } - else if (rudb24 >= (1ull << (32+9))) + else if (rudb24 >= (1ull << (32 + 9))) { rud = (uint32_t)rudb24 >> 10; /* RUD = 4*RUDb12 */ rmod = 5; /* Reff = RUD / 4 */ } - else if (rudb24 >= (1ull << (32+8))) + else if (rudb24 >= (1ull << (32 + 8))) { rud = (uint32_t)rudb24 >> 9; /* RUD = 8*RUDb12 */ rmod = 6; /* Reff = RUD / 8 */ } - else /* if (rudb24 >= (1ull << (32+7))) */ + else /* if (rudb24 >= (1ull << (32 + 7))) */ { rud = (uint32_t)rudb24 >> 8; /* RUD = 16*RUDb12 */ rmod = 7; /* Reff = RUD / 16 */ @@ -739,19 +739,20 @@ int cs2100_disable(FAR const struct cs2100_config_s *config) return ret; } -/******************************************************************************************** +/**************************************************************************** * Name: cs2100_dump * * Description: * Dump CS2100-CP registers to the SysLog * * Input Parameters: - * config - CS2100-CP configuration (Needed only for I2C access: i2c and i2caddr) + * config - CS2100-CP configuration (Needed only for I2C access: i2c and + * i2caddr) * * Returned Value: * Zero (OK) on success; a negated errno value on failure. * - ********************************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_CS2100CP_DEBUG int cs2100_dump(FAR const struct cs2100_config_s *config) diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 113fb97743..a791bce16d 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -55,7 +55,9 @@ /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ + /* Configuration ********************************************************************/ + /* This RTC implementation supports only date/time RTC hardware */ #ifndef CONFIG_RTC_DATETIME @@ -80,6 +82,7 @@ /************************************************************************************ * Priviate Types ************************************************************************************/ + /* This structure describes the state of the DS3231 chip. Only a single RTC is * supported. */ @@ -100,6 +103,7 @@ volatile bool g_rtc_enabled = false; /************************************************************************************ * Private Data ************************************************************************************/ + /* The state of the DS3231 chip. Only a single RTC is supported */ static struct ds3231_dev_s g_ds3231; @@ -329,6 +333,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) (seconds & DSXXXX_TIME_SEC_BCDMASK)); /* Format the return time */ + /* Return seconds (0-61) */ tp->tm_sec = rtc_bcd2bin(buffer[0] & DSXXXX_TIME_SEC_BCDMASK); @@ -427,23 +432,25 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } - #ifdef CONFIG_LIBC_LOCALTIME - if (localtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: localtime_r failed\n"); - return -EINVAL; - } +#ifdef CONFIG_LIBC_LOCALTIME + if (localtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: localtime_r failed\n"); + return -EINVAL; + } + #else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n"); - return -EINVAL; - } + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: gmtime_r failed\n"); + return -EINVAL; + } #endif rtc_dumptime(&newtm, "New time"); /* Construct the message */ + /* Write starting with the seconds regiser */ buffer[0] = DSXXXX_TIME_SECR; diff --git a/drivers/timers/mcp794xx.c b/drivers/timers/mcp794xx.c index e34643fd1e..314e0ea392 100644 --- a/drivers/timers/mcp794xx.c +++ b/drivers/timers/mcp794xx.c @@ -64,6 +64,7 @@ #define MCP794XX_OSCRUN_READ_RETRY 5 /* How many time to read OSCRUN status */ /* Configuration ************************************************************/ + /* This RTC implementation supports only date/time RTC hardware */ #ifndef CONFIG_RTC_DATETIME @@ -344,6 +345,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) (seconds & MCP794XX_RTCSEC_BCDMASK)); /* Format the return time */ + /* Return seconds (0-59) */ tp->tm_sec = rtc_bcd2bin(buffer[0] & MCP794XX_RTCSEC_BCDMASK); @@ -431,18 +433,19 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } - #ifdef CONFIG_LIBC_LOCALTIME - if (localtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: localtime_r failed\n"); - return -EINVAL; - } +#ifdef CONFIG_LIBC_LOCALTIME + if (localtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: localtime_r failed\n"); + return -EINVAL; + } + #else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n"); - return -EINVAL; - } + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: gmtime_r failed\n"); + return -EINVAL; + } #endif rtc_dumptime(&newtm, "New time"); @@ -501,6 +504,7 @@ int up_rtc_settime(FAR const struct timespec *tp) while ((wkday & MCP794XX_RTCWKDAY_OSCRUN) != 0 && retries > 0); /* Construct the message */ + /* Write starting with the seconds register */ buffer[0] = MCP794XX_REG_RTCSEC; diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index f162699f20..b836aafc88 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -55,7 +55,9 @@ /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ + /* Configuration ********************************************************************/ + /* This RTC implementation supports only date/time RTC hardware */ #ifndef CONFIG_RTC_DATETIME @@ -80,6 +82,7 @@ /************************************************************************************ * Priviate Types ************************************************************************************/ + /* This structure describes the state of the PCF85263 chip. Only a single RTC is * supported. */ @@ -100,6 +103,7 @@ volatile bool g_rtc_enabled = false; /************************************************************************************ * Private Data ************************************************************************************/ + /* The state of the PCF85263 chip. Only a single RTC is supported */ static struct pcf85263_dev_s g_pcf85263; @@ -328,6 +332,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) (seconds & PCF85263_RTC_SECONDS_MASK)); /* Format the return time */ + /* Return seconds (0-61) */ tp->tm_sec = rtc_bcd2bin(buffer[0] & PCF85263_RTC_SECONDS_MASK); @@ -410,23 +415,25 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } - #ifdef CONFIG_LIBC_LOCALTIME - if (localtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: localtime_r failed\n") - return -EINVAL; - } +#ifdef CONFIG_LIBC_LOCALTIME + if (localtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: localtime_r failed\n") + return -EINVAL; + } + #else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n") - return -EINVAL; - } + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: gmtime_r failed\n") + return -EINVAL; + } #endif rtc_dumptime(&tm, "New time"); /* Construct the message */ + /* Write starting with the 100ths of seconds register */ buffer[0] = PCF85263_RTC_100TH_SECONDS; diff --git a/drivers/timers/pwm.c b/drivers/timers/pwm.c index 7931ea5c60..a6afc57a54 100644 --- a/drivers/timers/pwm.c +++ b/drivers/timers/pwm.c @@ -454,7 +454,8 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_SETCHARACTERISTICS: { - FAR const struct pwm_info_s *info = (FAR const struct pwm_info_s *)((uintptr_t)arg); + FAR const struct pwm_info_s *info = + (FAR const struct pwm_info_s *)((uintptr_t)arg); DEBUGASSERT(info != NULL && lower->ops->start != NULL); pwm_dump("PWMIOC_SETCHARACTERISTICS", info, upper->started);