Char drivers should return -ENOTTY if CMD is not recognized

This commit is contained in:
Alan C. Assis
2020-06-06 14:21:44 -03:00
committed by Alan Carvalho de Assis
parent a254023e74
commit a7a272661e
10 changed files with 127 additions and 95 deletions
+32 -26
View File
@@ -97,7 +97,8 @@ static void pn532_unlock(FAR struct spi_dev_s *spi);
static int _open(FAR struct file *filep); static int _open(FAR struct file *filep);
static int _close(FAR struct file *filep); static int _close(FAR struct file *filep);
static ssize_t _read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t _read(FAR struct file *filep,
FAR char *buffer, size_t buflen);
static ssize_t _write(FAR struct file *filep, FAR const char *buffer, static ssize_t _write(FAR struct file *filep, FAR const char *buffer,
size_t buflen); size_t buflen);
static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg); static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg);
@@ -134,7 +135,7 @@ static const struct file_operations g_pn532fops =
static const uint8_t pn532ack[] = static const uint8_t pn532ack[] =
{ {
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 0x00, 0x00, 0xff, 0x00, 0xff, 0x00
}; };
/**************************************************************************** /****************************************************************************
@@ -218,7 +219,7 @@ static void pn532_frame_init(FAR struct pn532_frame *frame, uint8_t cmd)
static void pn532_frame_finish(FAR struct pn532_frame *frame) static void pn532_frame_finish(FAR struct pn532_frame *frame)
{ {
frame->lcs = pn532_checksum(frame->len); frame->lcs = pn532_checksum(frame->len);
frame->data[frame->len-1] = pn532_data_checksum(&frame->tfi, frame->len); frame->data[frame->len - 1] = pn532_data_checksum(&frame->tfi, frame->len);
frame->data[frame->len] = PN532_POSTAMBLE; frame->data[frame->len] = PN532_POSTAMBLE;
} }
@@ -266,10 +267,10 @@ bool pn532_rx_frame_is_valid(FAR struct pn532_frame *f, bool check_data)
if (check_data) if (check_data)
{ {
chk = pn532_data_checksum(&f->tfi, f->len); chk = pn532_data_checksum(&f->tfi, f->len);
if (chk != f->data[f->len-1]) if (chk != f->data[f->len - 1])
{ {
ctlserr("ERROR: Frame data checksum failed: calc=0x%X != 0x%X", ctlserr("ERROR: Frame data checksum failed: calc=0x%X != 0x%X",
chk, f->data[f->len-1]); chk, f->data[f->len - 1]);
return false; return false;
} }
} }
@@ -397,7 +398,8 @@ int pn532_read(FAR struct pn532_dev_s *dev, FAR uint8_t *buff, uint8_t n)
return n; return n;
} }
int pn532_read_more(FAR struct pn532_dev_s *dev, FAR uint8_t *buff, uint8_t n) int pn532_read_more(FAR struct pn532_dev_s *dev,
FAR uint8_t *buff, uint8_t n)
{ {
pn532_lock(dev->spi); pn532_lock(dev->spi);
pn532_select(dev); pn532_select(dev);
@@ -650,14 +652,14 @@ uint32_t pn532_write_passive_data(FAR struct pn532_dev_s *dev,
uint8_t address, FAR uint8_t *data, uint8_t address, FAR uint8_t *data,
uint8_t len) uint8_t len)
{ {
uint8_t cmd_buffer[8+7]; uint8_t cmd_buffer[8 + 7];
FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer; FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer;
uint8_t resp[20]; uint8_t resp[20];
uint32_t res = -EIO; uint32_t res = -EIO;
pn532_frame_init(f, PN532_COMMAND_INDATAEXCHANGE); pn532_frame_init(f, PN532_COMMAND_INDATAEXCHANGE);
f->data[1] = 1; /* max n cards at once */ f->data[1] = 1; /* max n cards at once */
f->data[2] = 0xA2; /* command WRITE */ f->data[2] = 0xa2; /* command WRITE */
f->data[3] = address; /* ADDRESS, 0 = serial */ f->data[3] = address; /* ADDRESS, 0 = serial */
memcpy(&f->data[4], data, len); memcpy(&f->data[4], data, len);
f->len += 7; f->len += 7;
@@ -672,9 +674,10 @@ uint32_t pn532_write_passive_data(FAR struct pn532_dev_s *dev,
{ {
dev->state = PN532_STATE_IDLE; dev->state = PN532_STATE_IDLE;
f = (FAR struct pn532_frame *) resp; f = (FAR struct pn532_frame *) resp;
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6); tracerx("passive target id resp:", (FAR uint8_t *)f,
f->len + 6);
if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1) if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE + 1)
{ {
res = f->data[1]; res = f->data[1];
} }
@@ -685,10 +688,11 @@ uint32_t pn532_write_passive_data(FAR struct pn532_dev_s *dev,
return res; return res;
} }
uint32_t pn532_read_passive_data(FAR struct pn532_dev_s *dev, uint8_t address, uint32_t pn532_read_passive_data(FAR struct pn532_dev_s *dev,
FAR uint8_t *data, uint8_t len) uint8_t address, FAR uint8_t *data,
uint8_t len)
{ {
uint8_t cmd_buffer[4+7]; uint8_t cmd_buffer[4 + 7];
FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer; FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer;
uint8_t resp[30]; uint8_t resp[30];
uint32_t res = -1; uint32_t res = -1;
@@ -704,13 +708,15 @@ uint32_t pn532_read_passive_data(FAR struct pn532_dev_s *dev, uint8_t address,
{ {
if (dev->state == PN532_STATE_DATA_READY) if (dev->state == PN532_STATE_DATA_READY)
{ {
if (pn532_read_frame(dev, (FAR struct pn532_frame *)resp, 25) == OK) if (pn532_read_frame(dev,
(FAR struct pn532_frame *)resp, 25) == OK)
{ {
dev->state = PN532_STATE_IDLE; dev->state = PN532_STATE_IDLE;
f = (FAR struct pn532_frame *) resp; f = (FAR struct pn532_frame *) resp;
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6); tracerx("passive target id resp:", (FAR uint8_t *)f,
f->len + 6);
if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE+1) if (f->data[0] == PN532_COMMAND_INDATAEXCHANGE + 1)
{ {
if (f->data[1] == 0 && data && len) if (f->data[1] == 0 && data && len)
{ {
@@ -729,7 +735,7 @@ uint32_t pn532_read_passive_data(FAR struct pn532_dev_s *dev, uint8_t address,
uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev, uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev,
uint8_t baudrate) uint8_t baudrate)
{ {
uint8_t cmd_buffer[4+7]; uint8_t cmd_buffer[4 + 7];
FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer; FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer;
uint8_t resp[20]; uint8_t resp[20];
uint32_t res = -EAGAIN; uint32_t res = -EAGAIN;
@@ -746,9 +752,9 @@ uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev,
f = (FAR struct pn532_frame *) resp; f = (FAR struct pn532_frame *) resp;
r = (FAR struct pn_poll_response *) &f->data[1]; r = (FAR struct pn_poll_response *) &f->data[1];
tracerx("passive target id resp:", (FAR uint8_t *)f, f->len+6); tracerx("passive target id resp:", (FAR uint8_t *)f, f->len + 6);
if (f->data[0] == PN532_COMMAND_INLISTPASSIVETARGET+1) if (f->data[0] == PN532_COMMAND_INLISTPASSIVETARGET + 1)
{ {
uint32_t cid = 0; uint32_t cid = 0;
@@ -783,13 +789,12 @@ uint32_t pn532_read_passive_target_id(FAR struct pn532_dev_s *dev,
} }
return res; return res;
} }
static int pn532_read_passive_target(FAR struct pn532_dev_s *dev, static int pn532_read_passive_target(FAR struct pn532_dev_s *dev,
uint8_t baudrate) uint8_t baudrate)
{ {
uint8_t cmd_buffer[4+7]; uint8_t cmd_buffer[4 + 7];
FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer; FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer;
pn532_frame_init(f, PN532_COMMAND_INLISTPASSIVETARGET); pn532_frame_init(f, PN532_COMMAND_INLISTPASSIVETARGET);
@@ -800,16 +805,17 @@ static int pn532_read_passive_target(FAR struct pn532_dev_s *dev,
return pn532_write_frame(dev, f); return pn532_write_frame(dev, f);
} }
bool pn532_set_rf_config(struct pn532_dev_s *dev, struct pn_rf_config_s *conf) bool pn532_set_rf_config(struct pn532_dev_s * dev,
struct pn_rf_config_s * conf)
{ {
bool res = false; bool res = false;
uint8_t cmd_buffer[15+7]; uint8_t cmd_buffer[15 + 7];
FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer; FAR struct pn532_frame *f = (FAR struct pn532_frame *) cmd_buffer;
pn532_frame_init(f, PN532_COMMAND_RFCONFIGURATION); pn532_frame_init(f, PN532_COMMAND_RFCONFIGURATION);
f->data[1] = conf->cfg_item; f->data[1] = conf->cfg_item;
memcpy(&f->data[2], conf->config, conf->data_size); memcpy(&f->data[2], conf->config, conf->data_size);
f->len += conf->data_size+1; f->len += conf->data_size + 1;
pn532_frame_finish(f); pn532_frame_finish(f);
if (pn532_write_frame(dev, f) == OK) if (pn532_write_frame(dev, f) == OK)
@@ -943,7 +949,7 @@ static ssize_t _read(FAR struct file *filep, FAR char *buffer, size_t buflen)
dev = inode->i_private; dev = inode->i_private;
uint32_t id = pn532_read_passive_target_id(dev, PN532_MIFARE_ISO14443A); uint32_t id = pn532_read_passive_target_id(dev, PN532_MIFARE_ISO14443A);
if (id != 0xFFFFFFFF) if (id != 0xffffffff)
{ {
if (buffer) if (buffer)
{ {
@@ -1102,7 +1108,7 @@ static int _ioctl(FAR struct file *filep, int cmd, unsigned long arg)
default: default:
ctlserr("ERROR: Unrecognized cmd: %d\n", cmd); ctlserr("ERROR: Unrecognized cmd: %d\n", cmd);
ret = -EINVAL; ret = -ENOTTY;
break; break;
} }
+1 -1
View File
@@ -828,7 +828,7 @@ static int ee24xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch (cmd) switch (cmd)
{ {
default: default:
ret = -EINVAL; ret = -ENOTTY;
} }
return ret; return ret;
+1 -1
View File
@@ -812,7 +812,7 @@ static int ee25xx_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch (cmd) switch (cmd)
{ {
default: default:
ret = -EINVAL; ret = -ENOTTY;
} }
return ret; return ret;
+1
View File
@@ -368,6 +368,7 @@ static int altmdm_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
default: default:
m_err("Unrecognized cmd: 0x%08x\n", cmd); m_err("Unrecognized cmd: 0x%08x\n", cmd);
ret = -ENOTTY;
break; break;
} }
+29 -28
View File
@@ -56,6 +56,7 @@
****************************************************************************/ ****************************************************************************/
/* Debug ********************************************************************/ /* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing the modem driver */ /* Non-standard debug that may be enabled just for testing the modem driver */
#ifdef CONFIG_MODEM_U_BLOX_DEBUG #ifdef CONFIG_MODEM_U_BLOX_DEBUG
@@ -74,29 +75,29 @@
struct ubxmdm_upper struct ubxmdm_upper
{ {
FAR char* path; /* Registration path */ FAR char * path; /* Registration path */
/* The contained lower-half driver. */ /* The contained lower-half driver. */
FAR struct ubxmdm_lower* lower; FAR struct ubxmdm_lower * lower;
}; };
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
static ssize_t ubxmdm_read (FAR struct file* filep, static ssize_t ubxmdm_read (FAR struct file * filep,
FAR char* buffer, FAR char * buffer,
size_t buflen); size_t buflen);
static ssize_t ubxmdm_write(FAR struct file* filep, static ssize_t ubxmdm_write(FAR struct file * filep,
FAR const char* buffer, FAR const char * buffer,
size_t buflen); size_t buflen);
static int ubxmdm_ioctl(FAR struct file* filep, static int ubxmdm_ioctl(FAR struct file * filep,
int cmd, int cmd,
unsigned long arg); unsigned long arg);
static int ubxmdm_poll (FAR struct file* filep, static int ubxmdm_poll (FAR struct file * filep,
FAR struct pollfd* fds, FAR struct pollfd * fds,
bool setup); bool setup);
/**************************************************************************** /****************************************************************************
@@ -118,29 +119,29 @@ static const struct file_operations ubxmdm_fops =
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static ssize_t ubxmdm_read(FAR struct file* filep, static ssize_t ubxmdm_read(FAR struct file * filep,
FAR char* buffer, FAR char * buffer,
size_t len) size_t len)
{ {
return 0; /* Return EOF */ return 0; /* Return EOF */
} }
static ssize_t ubxmdm_write(FAR struct file* filep, static ssize_t ubxmdm_write(FAR struct file * filep,
FAR const char* buffer, FAR const char * buffer,
size_t len) size_t len)
{ {
return len; /* Say that everything was written */ return len; /* Say that everything was written */
} }
static int ubxmdm_ioctl(FAR struct file* filep, static int ubxmdm_ioctl(FAR struct file * filep,
int cmd, int cmd,
unsigned long arg) unsigned long arg)
{ {
FAR struct inode* inode = filep->f_inode; FAR struct inode * inode = filep->f_inode;
FAR struct ubxmdm_upper* upper; FAR struct ubxmdm_upper * upper;
FAR struct ubxmdm_lower* lower; FAR struct ubxmdm_lower * lower;
int ret; int ret;
FAR struct ubxmdm_status* status; FAR struct ubxmdm_status * status;
m_info("cmd: %d arg: %ld\n", cmd, arg); m_info("cmd: %d arg: %ld\n", cmd, arg);
upper = inode->i_private; upper = inode->i_private;
@@ -209,7 +210,7 @@ static int ubxmdm_ioctl(FAR struct file* filep,
case MODEM_IOC_GETSTATUS: case MODEM_IOC_GETSTATUS:
if (lower->ops->getstatus) if (lower->ops->getstatus)
{ {
status = (FAR struct ubxmdm_status*) ((uintptr_t) arg); status = (FAR struct ubxmdm_status *) ((uintptr_t) arg);
if (status) if (status)
{ {
ret = lower->ops->getstatus(lower, status); ret = lower->ops->getstatus(lower, status);
@@ -239,7 +240,7 @@ static int ubxmdm_ioctl(FAR struct file* filep,
} }
else else
{ {
ret = -ENOSYS; ret = -ENOTTY;
} }
break; break;
@@ -248,8 +249,8 @@ static int ubxmdm_ioctl(FAR struct file* filep,
return ret; return ret;
} }
static int ubxmdm_poll(FAR struct file* filep, static int ubxmdm_poll(FAR struct file * filep,
FAR struct pollfd* fds, FAR struct pollfd * fds,
bool setup) bool setup)
{ {
if (setup) if (setup)
@@ -268,15 +269,15 @@ static int ubxmdm_poll(FAR struct file* filep,
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
FAR void* ubxmdm_register(FAR const char *path, FAR void * ubxmdm_register(FAR const char * path,
FAR struct ubxmdm_lower *lower) FAR struct ubxmdm_lower * lower)
{ {
FAR struct ubxmdm_upper *upper; FAR struct ubxmdm_upper *upper;
int ret; int ret;
DEBUGASSERT(path && lower); DEBUGASSERT(path && lower);
upper = (FAR struct ubxmdm_upper*) upper = (FAR struct ubxmdm_upper *)
kmm_zalloc(sizeof(struct ubxmdm_upper)); kmm_zalloc(sizeof(struct ubxmdm_upper));
if (!upper) if (!upper)
{ {
@@ -299,7 +300,7 @@ FAR void* ubxmdm_register(FAR const char *path,
goto errout_with_path; goto errout_with_path;
} }
return (FAR void*) upper; return (FAR void *) upper;
errout_with_path: errout_with_path:
kmm_free(upper->path); kmm_free(upper->path);
@@ -316,7 +317,7 @@ void ubxmdm_unregister(FAR void *handle)
FAR struct ubxmdm_upper *upper; FAR struct ubxmdm_upper *upper;
FAR struct ubxmdm_lower *lower; FAR struct ubxmdm_lower *lower;
upper = (FAR struct ubxmdm_upper*) handle; upper = (FAR struct ubxmdm_upper *) handle;
DEBUGASSERT(upper != NULL); DEBUGASSERT(upper != NULL);
lower = upper->lower; lower = upper->lower;
DEBUGASSERT(lower != NULL); DEBUGASSERT(lower != NULL);
+38 -19
View File
@@ -153,8 +153,9 @@ static const struct file_operations mtdconfig_fops =
* *
****************************************************************************/ ****************************************************************************/
static int mtdconfig_readbytes(FAR struct mtdconfig_struct_s *dev, int offset, static int mtdconfig_readbytes(FAR struct mtdconfig_struct_s *dev,
FAR uint8_t *pdata, int readlen) int offset, FAR uint8_t *pdata,
int readlen)
{ {
off_t bytestoread = readlen; off_t bytestoread = readlen;
off_t bytesthisblock; off_t bytesthisblock;
@@ -194,7 +195,8 @@ static int mtdconfig_readbytes(FAR struct mtdconfig_struct_s *dev, int offset,
while (bytestoread > 0) while (bytestoread > 0)
{ {
if (bytesthisblock < dev->blocksize || bytestoread < dev->blocksize) if (bytesthisblock < dev->blocksize ||
bytestoread < dev->blocksize)
{ {
/* Copy to temp buffer first...don't need the whole block */ /* Copy to temp buffer first...don't need the whole block */
@@ -269,7 +271,7 @@ static int mtdconfig_writebytes(FAR struct mtdconfig_struct_s *dev,
else else
#endif #endif
/* Perform the write using the block write method of the MTD */ /* Perform the write using the block write method of the MTD */
{ {
uint16_t block; uint16_t block;
@@ -681,8 +683,8 @@ static off_t mtdconfig_ramconsolidate(FAR struct mtdconfig_struct_s *dev)
/* Now write the item to the current dst_offset location. */ /* Now write the item to the current dst_offset location. */
ret = mtdconfig_writebytes(dev, dst_offset, (FAR uint8_t *)phdr, ret = mtdconfig_writebytes(dev, dst_offset,
sizeof(hdr)); (FAR uint8_t *)phdr, sizeof(hdr));
if (ret != sizeof(hdr)) if (ret != sizeof(hdr))
{ {
/* I/O Error! */ /* I/O Error! */
@@ -707,8 +709,9 @@ static off_t mtdconfig_ramconsolidate(FAR struct mtdconfig_struct_s *dev)
/* Test if enough space in dst block for another header */ /* Test if enough space in dst block for another header */
if (dst_offset + sizeof(hdr) >= (dst_block + 1) * dev->erasesize || if ((dst_offset + sizeof(hdr) >= (dst_block + 1) *
dst_offset == (dst_block + 1) * dev->erasesize) dev->erasesize) || (dst_offset == (dst_block + 1) *
dev->erasesize))
{ {
dst_block++; dst_block++;
dst_offset = dst_block * dev->erasesize + dst_offset = dst_block * dev->erasesize +
@@ -840,7 +843,8 @@ static off_t mtdconfig_consolidate(FAR struct mtdconfig_struct_s *dev)
/* Scan all headers and move them to the src_offset */ /* Scan all headers and move them to the src_offset */
retry_relocate: retry_relocate:
bytes = MTD_READ(dev->mtd, src_offset, sizeof(hdr), (FAR uint8_t *)&hdr); bytes = MTD_READ(dev->mtd, src_offset,
sizeof(hdr), (FAR uint8_t *)&hdr);
if (bytes != sizeof(hdr)) if (bytes != sizeof(hdr))
{ {
/* I/O Error! */ /* I/O Error! */
@@ -870,13 +874,17 @@ retry_relocate:
} }
else else
{ {
/* Test if this entry will fit in the current destination block */ /* Test if this entry will fit in the current destination
* block.
*/
bytes_left_in_block = (dst_block + 1) * dev->erasesize - bytes_left_in_block = (dst_block + 1) * dev->erasesize -
dst_offset; dst_offset;
if (hdr.len + sizeof(hdr) > bytes_left_in_block) if (hdr.len + sizeof(hdr) > bytes_left_in_block)
{ {
/* Item doesn't fit in the block. Advance to the next one */ /* Item doesn't fit in the block. Advance to the next
* one.
*/
/* Update control variables */ /* Update control variables */
@@ -893,8 +901,8 @@ retry_relocate:
/* Copy this entry to the destination */ /* Copy this entry to the destination */
ret = mtdconfig_writebytes(dev, dst_offset, (FAR uint8_t *)&hdr, ret = mtdconfig_writebytes(dev, dst_offset,
sizeof(hdr)); (FAR uint8_t *)&hdr, sizeof(hdr));
if (ret != sizeof(hdr)) if (ret != sizeof(hdr))
{ {
/* I/O Error! */ /* I/O Error! */
@@ -987,10 +995,13 @@ retry_relocate:
if (dst_offset + sizeof(hdr) >= (dst_block + 1) * dev->erasesize) if (dst_offset + sizeof(hdr) >= (dst_block + 1) * dev->erasesize)
{ {
/* No room at end of dst block for another header. Go to next block. */ /* No room at end of dst block for another header.
* Go to next block.
*/
dst_block++; dst_block++;
dst_offset = dst_block * dev->erasesize + CONFIGDATA_BLOCK_HDR_SIZE; dst_offset = dst_block * dev->erasesize +
CONFIGDATA_BLOCK_HDR_SIZE;
DEBUGASSERT(dst_block != src_block); DEBUGASSERT(dst_block != src_block);
} }
} }
@@ -1349,7 +1360,8 @@ retry_find:
hdr.len = pdata->len; hdr.len = pdata->len;
hdr.flags = MTD_ERASED_FLAGS; hdr.flags = MTD_ERASED_FLAGS;
ret = mtdconfig_writebytes(dev, offset, (FAR uint8_t *)&hdr, sizeof(hdr)); ret = mtdconfig_writebytes(dev, offset,
(FAR uint8_t *)&hdr, sizeof(hdr));
if (ret != sizeof(hdr)) if (ret != sizeof(hdr))
{ {
/* Cannot write even header! */ /* Cannot write even header! */
@@ -1444,6 +1456,7 @@ static int mtdconfig_getconfig(FAR struct mtdconfig_struct_s *dev,
} }
errout: errout:
/* Free the buffer */ /* Free the buffer */
kmm_free(dev->buffer); kmm_free(dev->buffer);
@@ -1510,7 +1523,7 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
FAR struct config_data_s *pdata; FAR struct config_data_s *pdata;
struct mtdconfig_header_s hdr; struct mtdconfig_header_s hdr;
off_t bytes_to_read; off_t bytes_to_read;
int ret = -ENOSYS; int ret = -ENOTTY;
switch (cmd) switch (cmd)
{ {
@@ -1531,6 +1544,7 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
break; break;
case CFGDIOC_DELCONFIG: case CFGDIOC_DELCONFIG:
/* Set the config item */ /* Set the config item */
pdata = (FAR struct config_data_s *)arg; pdata = (FAR struct config_data_s *)arg;
@@ -1538,6 +1552,7 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
break; break;
case CFGDIOC_FIRSTCONFIG: case CFGDIOC_FIRSTCONFIG:
/* Get the the first config item */ /* Get the the first config item */
pdata = (FAR struct config_data_s *)arg; pdata = (FAR struct config_data_s *)arg;
@@ -1585,6 +1600,7 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
break; break;
case CFGDIOC_NEXTCONFIG: case CFGDIOC_NEXTCONFIG:
/* Get the next config item */ /* Get the next config item */
pdata = (FAR struct config_data_s *)arg; pdata = (FAR struct config_data_s *)arg;
@@ -1601,7 +1617,8 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
/* Test if the config item is valid */ /* Test if the config item is valid */
#ifdef CONFIG_MTD_CONFIG_NAMED #ifdef CONFIG_MTD_CONFIG_NAMED
if (dev->readoff != 0 && hdr.name[0] != CONFIG_MTD_CONFIG_ERASEDVALUE) if (dev->readoff != 0 &&
hdr.name[0] != CONFIG_MTD_CONFIG_ERASEDVALUE)
#else #else
if (dev->readoff != 0 && hdr.id != MTD_ERASED_ID) if (dev->readoff != 0 && hdr.id != MTD_ERASED_ID)
#endif #endif
@@ -1639,6 +1656,7 @@ static int mtdconfig_ioctl(FAR struct file *filep, int cmd,
break; break;
case MTDIOC_BULKERASE: case MTDIOC_BULKERASE:
/* Call the MTD's ioctl for this */ /* Call the MTD's ioctl for this */
if (dev->mtd->ioctl) if (dev->mtd->ioctl)
@@ -1703,7 +1721,8 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
* from the size of a pointer). * from the size of a pointer).
*/ */
ret = MTD_IOCTL(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo)); ret = MTD_IOCTL(mtd, MTDIOC_GEOMETRY,
(unsigned long)((uintptr_t)&geo));
if (ret < 0) if (ret < 0)
{ {
ferr("ERROR: MTD ioctl(MTDIOC_GEOMETRY) failed: %d\n", ret); ferr("ERROR: MTD ioctl(MTDIOC_GEOMETRY) failed: %d\n", ret);
+1 -1
View File
@@ -1464,7 +1464,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return OK; return OK;
} }
return -EBADFD; return -ENOTTY;
} }
/**************************************************************************** /****************************************************************************
+20 -16
View File
@@ -116,7 +116,7 @@ static const struct file_operations g_timerops =
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/************************************************************************************ /****************************************************************************
* Name: timer_notifier * Name: timer_notifier
* *
* Description: * Description:
@@ -124,7 +124,7 @@ static const struct file_operations g_timerops =
* *
* REVISIT: This function prototype is insufficient to support signaling * REVISIT: This function prototype is insufficient to support signaling
* *
************************************************************************************/ ****************************************************************************/
static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg) static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg)
{ {
@@ -141,13 +141,13 @@ static bool timer_notifier(FAR uint32_t *next_interval_us, FAR void *arg)
return true; return true;
} }
/************************************************************************************ /****************************************************************************
* Name: timer_open * Name: timer_open
* *
* Description: * Description:
* This function is called whenever the timer device is opened. * This function is called whenever the timer device is opened.
* *
************************************************************************************/ ****************************************************************************/
static int timer_open(FAR struct file *filep) static int timer_open(FAR struct file *filep)
{ {
@@ -192,13 +192,13 @@ errout:
return ret; return ret;
} }
/************************************************************************************ /****************************************************************************
* Name: timer_close * Name: timer_close
* *
* Description: * Description:
* This function is called when the timer device is closed. * This function is called when the timer device is closed.
* *
************************************************************************************/ ****************************************************************************/
static int timer_close(FAR struct file *filep) static int timer_close(FAR struct file *filep)
{ {
@@ -229,28 +229,29 @@ static int timer_close(FAR struct file *filep)
return OK; return OK;
} }
/************************************************************************************ /****************************************************************************
* Name: timer_read * Name: timer_read
* *
* Description: * Description:
* A dummy read method. This is provided only to satisfy the VFS layer. * A dummy read method. This is provided only to satisfy the VFS layer.
* *
************************************************************************************/ ****************************************************************************/
static ssize_t timer_read(FAR struct file *filep, FAR char *buffer, size_t buflen) static ssize_t timer_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{ {
/* Return zero -- usually meaning end-of-file */ /* Return zero -- usually meaning end-of-file */
return 0; return 0;
} }
/************************************************************************************ /****************************************************************************
* Name: timer_write * Name: timer_write
* *
* Description: * Description:
* A dummy write method. This is provided only to satisfy the VFS layer. * A dummy write method. This is provided only to satisfy the VFS layer.
* *
************************************************************************************/ ****************************************************************************/
static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer, static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen) size_t buflen)
@@ -258,14 +259,14 @@ static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer,
return 0; return 0;
} }
/************************************************************************************ /****************************************************************************
* Name: timer_ioctl * Name: timer_ioctl
* *
* Description: * Description:
* The standard ioctl method. This is where ALL of the timer work is * The standard ioctl method. This is where ALL of the timer work is
* done. * done.
* *
************************************************************************************/ ****************************************************************************/
static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
@@ -393,7 +394,8 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
if (notify != NULL) if (notify != NULL)
{ {
memcpy(&upper->notify, notify, sizeof(*notify)); memcpy(&upper->notify, notify, sizeof(*notify));
ret = timer_setcallback((FAR void *)upper, timer_notifier, upper); ret = timer_setcallback((FAR void *)upper,
timer_notifier, upper);
} }
else else
{ {
@@ -422,7 +424,9 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
break; break;
/* Any unrecognized IOCTL commands might be platform-specific ioctl commands */ /* Any unrecognized IOCTL commands might be platform-specific ioctl
* commands
*/
default: default:
{ {
@@ -439,7 +443,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
else else
{ {
ret = -ENOSYS; ret = -ENOTTY;
} }
} }
break; break;
+3 -2
View File
@@ -183,7 +183,8 @@ static void watchdog_automonitor_idle(FAR struct pm_callback_s *cb,
#endif #endif
#ifdef CONFIG_WATCHDOG_AUTOMONITOR #ifdef CONFIG_WATCHDOG_AUTOMONITOR
static void watchdog_automonitor_start(FAR struct watchdog_upperhalf_s *upper) static void watchdog_automonitor_start(FAR struct watchdog_upperhalf_s
*upper)
{ {
FAR struct watchdog_lowerhalf_s *lower = upper->lower; FAR struct watchdog_lowerhalf_s *lower = upper->lower;
@@ -549,7 +550,7 @@ static int wdog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
else else
{ {
ret = -ENOSYS; ret = -ENOTTY;
} }
} }
break; break;
+1 -1
View File
@@ -2199,7 +2199,7 @@ static int usbhost_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
default: default:
ret = -EINVAL; ret = -ENOTTY;
goto errout; goto errout;
} }