Skip to content

Commit

Permalink
Call nxsem_destroy or nxmutex_destry in the error path
Browse files Browse the repository at this point in the history
1.Don't check the return value of nxsem_init or nxmutex_init
2.Fix some style issue

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
anjiahao1 authored and pkarashchenko committed Oct 30, 2022
1 parent 99cfffc commit d7b4e91
Show file tree
Hide file tree
Showing 53 changed files with 606 additions and 619 deletions.
2 changes: 1 addition & 1 deletion arch/arm/src/tiva/common/tiva_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ int tivacan_rxhandler(int argc, char** argv)
struct can_msg_s msg;

#ifdef CONFIG_CAN_ERRORS
int ret;
int ret;
#endif

/* argv[0] contains the thread name */
Expand Down
2 changes: 1 addition & 1 deletion binfmt/libnxflat/libnxflat_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
FAR struct nxflat_hdr_s *hdr;
FAR const struct symtab_s *symbol;

char *symname;
FAR char *symname;
uint32_t offset;
uint16_t nimports;
#ifdef CONFIG_ARCH_ADDRENV
Expand Down
4 changes: 2 additions & 2 deletions boards/arm/kinetis/freedom-k28f/src/k28_usbhshost.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ static void usb_msc_disconnect(void *arg)

int k28_usbhost_initialize(void)
{
int ret;
int ret;
# ifdef HAVE_USB_AUTOMOUNTER
int index;
int index;
# endif

/* First, register all of the class drivers needed to support the drivers
Expand Down
7 changes: 5 additions & 2 deletions drivers/analog/comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static int comp_open(FAR struct file *filep)

static int comp_close(FAR struct file *filep)
{
FAR struct inode *inode = filep->f_inode;
FAR struct inode *inode = filep->f_inode;
FAR struct comp_dev_s *dev = inode->i_private;
irqstate_t flags;
int ret;
Expand Down Expand Up @@ -363,16 +363,19 @@ int comp_register(FAR const char *path, FAR struct comp_dev_s *dev)
if (ret < 0)
{
aerr("ERROR: Failed to bind callbacks: %d\n", ret);
nxmutex_destroy(&dev->ad_lock);
nxsem_destroy(&dev->ad_readsem);
return ret;
}
}

/* Register the COMP character driver */

ret = register_driver(path, &comp_fops, 0444, dev);
ret = register_driver(path, &comp_fops, 0444, dev);
if (ret < 0)
{
nxmutex_destroy(&dev->ad_lock);
nxsem_destroy(&dev->ad_readsem);
}

return ret;
Expand Down
7 changes: 1 addition & 6 deletions drivers/analog/ltc1867l.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,7 @@ int ltc1867l_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
adcpriv->channel_config = channel_config;
adcpriv->channel_config_count = channel_config_count;

ret = nxmutex_init(&adcpriv->lock);
if (ret < 0)
{
kmm_free(adcpriv);
return ret;
}
nxmutex_init(&adcpriv->lock);

adcdev = (FAR struct adc_dev_s *)kmm_malloc(sizeof(struct adc_dev_s));
if (adcdev == NULL)
Expand Down
4 changes: 1 addition & 3 deletions drivers/audio/cs4344.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ FAR struct audio_lowerhalf_s *cs4344_initialize(FAR struct i2s_dev_s *i2s)

/* Allocate a CS4344 device structure */

priv = (FAR struct cs4344_dev_s *) kmm_zalloc(sizeof(struct cs4344_dev_s));
priv = (FAR struct cs4344_dev_s *)kmm_zalloc(sizeof(struct cs4344_dev_s));
if (priv)
{
/* Initialize the CS4344 device structure. Since we used kmm_zalloc,
Expand All @@ -1460,7 +1460,5 @@ FAR struct audio_lowerhalf_s *cs4344_initialize(FAR struct i2s_dev_s *i2s)
return &priv->dev;
}

nxmutex_destroy(&priv->pendlock);
kmm_free(priv);
return NULL;
}
40 changes: 18 additions & 22 deletions drivers/can/mcp2515.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,27 @@ enum can_state_s

struct mcp2515_can_s
{
struct mcp2515_config_s *config; /* The constant configuration */
uint8_t state; /* See enum can_state_s */
uint8_t nalloc; /* Number of allocated filters */
mutex_t lock; /* Enforces mutually exclusive access */
sem_t txfsem; /* Used to wait for TX FIFO availability */
uint32_t btp; /* Current bit timing */
uint8_t rxints; /* Configured RX interrupts */
uint8_t txints; /* Configured TX interrupts */
FAR struct mcp2515_config_s *config; /* The constant configuration */

uint8_t state; /* See enum can_state_s */
uint8_t nalloc; /* Number of allocated filters */
mutex_t lock; /* Enforces mutually exclusive access */
sem_t txfsem; /* Used to wait for TX FIFO availability */
uint32_t btp; /* Current bit timing */
uint8_t rxints; /* Configured RX interrupts */
uint8_t txints; /* Configured TX interrupts */
#ifdef CONFIG_CAN_ERRORS
uint32_t olderrors; /* Used to detect the changes in error states */
uint32_t olderrors; /* Used to detect the changes in error states */
#endif
uint8_t filters; /* Standard/Extende filter bit allocator. */
uint8_t txbuffers; /* TX Buffers bit allocator. */
uint8_t filters; /* Standard/Extende filter bit allocator. */
uint8_t txbuffers; /* TX Buffers bit allocator. */

FAR uint8_t *spi_txbuf;
FAR uint8_t *spi_rxbuf;
#ifdef CONFIG_MCP2515_REGDEBUG
uintptr_t regaddr; /* Last register address read */
uint32_t regval; /* Last value read from the register */
unsigned int count; /* Number of times that the value was read */
uintptr_t regaddr; /* Last register address read */
uint32_t regval; /* Last value read from the register */
unsigned int count; /* Number of times that the value was read */
#endif
};

Expand Down Expand Up @@ -1182,14 +1183,9 @@ static void mcp2515_reset_lowlevel(FAR struct mcp2515_can_s *priv)

nxsig_usleep(1000);

/* Make sure that all buffers are released.
*
* REVISIT: What if a thread is waiting for a buffer? The following
* will not wake up any waiting threads.
*/
/* Make sure that all buffers are released. */

nxsem_destroy(&priv->txfsem);
nxsem_init(&priv->txfsem, 0, MCP2515_NUM_TX_BUFFERS);
nxsem_reset(&priv->txfsem, MCP2515_NUM_TX_BUFFERS);
priv->txbuffers = 0b111;

/* Define the current state and unlock */
Expand Down Expand Up @@ -2136,7 +2132,7 @@ static void mcp2515_receive(FAR struct can_dev_s *dev, uint8_t offset)

/* Save the message data */

ret = can_receive(dev, &hdr, (FAR uint8_t *) & RXREGVAL(MCP2515_RXB0D0));
ret = can_receive(dev, &hdr, (FAR uint8_t *)&RXREGVAL(MCP2515_RXB0D0));

if (ret < 0)
{
Expand Down
7 changes: 4 additions & 3 deletions drivers/input/ads7843e.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ static int ads7843e_interrupt(int irq, FAR void *context, FAR void *arg)
static int ads7843e_open(FAR struct file *filep)
{
#ifdef CONFIG_ADS7843E_REFCNT
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct ads7843e_dev_s *priv;
uint8_t tmp;
int ret;
Expand Down Expand Up @@ -772,7 +772,7 @@ static int ads7843e_open(FAR struct file *filep)
static int ads7843e_close(FAR struct file *filep)
{
#ifdef CONFIG_ADS7843E_REFCNT
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct ads7843e_dev_s *priv;
int ret;

Expand Down Expand Up @@ -943,7 +943,7 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer,

static int ads7843e_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct ads7843e_dev_s *priv;
int ret;

Expand Down Expand Up @@ -1214,6 +1214,7 @@ int ads7843e_register(FAR struct spi_dev_s *spi,

errout_with_priv:
nxmutex_destroy(&priv->devlock);
nxsem_destroy(&priv->waitsem);
#ifdef CONFIG_ADS7843E_MULTIPLE
kmm_free(priv);
#endif
Expand Down
15 changes: 8 additions & 7 deletions drivers/input/ft5x06.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ static ssize_t ft5x06_read(FAR struct file *filep, FAR char *buffer,
size_t len)
{
FAR struct inode *inode;
FAR struct ft5x06_dev_s *priv;
FAR struct ft5x06_dev_s *priv;
int ret;

DEBUGASSERT(filep);
Expand Down Expand Up @@ -921,9 +921,9 @@ static ssize_t ft5x06_read(FAR struct file *filep, FAR char *buffer,

static int ft5x06_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct ft5x06_dev_s *priv;
int ret;
int ret;

iinfo("cmd: %d arg: %ld\n", cmd, arg);
DEBUGASSERT(filep);
Expand Down Expand Up @@ -975,12 +975,12 @@ static int ft5x06_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
****************************************************************************/

static int ft5x06_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup)
bool setup)
{
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct ft5x06_dev_s *priv;
int ret;
int i;
int ret;
int i;

iinfo("setup: %d\n", (int)setup);
DEBUGASSERT(filep && fds);
Expand Down Expand Up @@ -1176,6 +1176,7 @@ int ft5x06_register(FAR struct i2c_master_s *i2c,

errout_with_priv:
nxmutex_destroy(&priv->devlock);
nxsem_destroy(&priv->waitsem);
kmm_free(priv);
return ret;
}
7 changes: 4 additions & 3 deletions drivers/input/max11802.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static int max11802_interrupt(int irq, FAR void *context, FAR void *arg)
static int max11802_open(FAR struct file *filep)
{
#ifdef CONFIG_MAX11802_REFCNT
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct max11802_dev_s *priv;
uint8_t tmp;
int ret;
Expand Down Expand Up @@ -765,7 +765,7 @@ static int max11802_open(FAR struct file *filep)
static int max11802_close(FAR struct file *filep)
{
#ifdef CONFIG_MAX11802_REFCNT
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct max11802_dev_s *priv;
int ret;

Expand Down Expand Up @@ -936,7 +936,7 @@ static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer,

static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode;
FAR struct inode *inode;
FAR struct max11802_dev_s *priv;
int ret;

Expand Down Expand Up @@ -1248,6 +1248,7 @@ int max11802_register(FAR struct spi_dev_s *spi,

errout_with_priv:
nxmutex_destroy(&priv->devlock);
nxsem_destroy(&priv->waitsem);
#ifdef CONFIG_MAX11802_MULTIPLE
kmm_free(priv);
#endif
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/nunchuck.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int nunchuck_sample(FAR struct nunchuck_dev_s *priv,
{
uint8_t cmd[2];
uint8_t data[6];
static bool initialized = false;
static bool initialized;

if (!initialized)
{
Expand Down
Loading

0 comments on commit d7b4e91

Please sign in to comment.