mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
drivers/can/can.c: Fix errors with pointers when using internal OS interface (#118)
Author: Gregory Nutt <gnutt@nuttx.org> Run all .c and .h files in last PR through tools/nxstyle and correct all coding standard complaints. Author: Oleg <ev.mipt@gmail.com> * Fix CAN driver to work with internal OS interfaces. Store internal file pointer in f_priv and use it then to distinct readers (See issue #111) * Store reader pointer in f_priv instead of filep * Don't need in filep in can_reader_s
This commit is contained in:
+9
-24
@@ -390,7 +390,7 @@ static FAR struct can_reader_s *init_can_reader(FAR struct file *filep)
|
|||||||
reader->fifo.rx_tail = 0;
|
reader->fifo.rx_tail = 0;
|
||||||
|
|
||||||
nxsem_init(&reader->fifo.rx_sem, 0, 1);
|
nxsem_init(&reader->fifo.rx_sem, 0, 1);
|
||||||
reader->filep = filep;
|
filep->f_priv = reader;
|
||||||
|
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
@@ -509,7 +509,8 @@ static int can_close(FAR struct file *filep)
|
|||||||
|
|
||||||
list_for_every_safe(&dev->cd_readers, node, tmp)
|
list_for_every_safe(&dev->cd_readers, node, tmp)
|
||||||
{
|
{
|
||||||
if (((FAR struct can_reader_s *)node)->filep == filep)
|
if (((FAR struct can_reader_s *)node) ==
|
||||||
|
((FAR struct can_reader_s *)filep->f_priv))
|
||||||
{
|
{
|
||||||
list_delete(node);
|
list_delete(node);
|
||||||
kmm_free(node);
|
kmm_free(node);
|
||||||
@@ -517,6 +518,8 @@ static int can_close(FAR struct file *filep)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filep->f_priv = NULL;
|
||||||
|
|
||||||
/* Decrement the references to the driver. If the reference count will
|
/* Decrement the references to the driver. If the reference count will
|
||||||
* decrement to 0, then uninitialize the driver.
|
* decrement to 0, then uninitialize the driver.
|
||||||
*/
|
*/
|
||||||
@@ -574,7 +577,6 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
FAR struct inode *inode = filep->f_inode;
|
FAR struct inode *inode = filep->f_inode;
|
||||||
FAR struct can_dev_s *dev = inode->i_private;
|
FAR struct can_dev_s *dev = inode->i_private;
|
||||||
FAR struct can_reader_s *reader = NULL;
|
FAR struct can_reader_s *reader = NULL;
|
||||||
FAR struct list_node *node;
|
|
||||||
FAR struct can_rxfifo_s *fifo;
|
FAR struct can_rxfifo_s *fifo;
|
||||||
size_t nread;
|
size_t nread;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
@@ -630,16 +632,8 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_CAN_ERRORS */
|
#endif /* CONFIG_CAN_ERRORS */
|
||||||
|
|
||||||
list_for_every(&dev->cd_readers, node)
|
DEBUGASSERT(filep->f_priv != NULL);
|
||||||
{
|
reader = (FAR struct can_reader_s *)filep->f_priv;
|
||||||
if (((FAR struct can_reader_s *) node)->filep == filep)
|
|
||||||
{
|
|
||||||
reader = (FAR struct can_reader_s *)node;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUGASSERT(reader != NULL);
|
|
||||||
|
|
||||||
fifo = &reader->fifo;
|
fifo = &reader->fifo;
|
||||||
|
|
||||||
@@ -1027,7 +1021,6 @@ static int can_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
FAR struct inode *inode = (FAR struct inode *)filep->f_inode;
|
FAR struct inode *inode = (FAR struct inode *)filep->f_inode;
|
||||||
FAR struct can_dev_s *dev = (FAR struct can_dev_s *)inode->i_private;
|
FAR struct can_dev_s *dev = (FAR struct can_dev_s *)inode->i_private;
|
||||||
FAR struct can_reader_s *reader = NULL;
|
FAR struct can_reader_s *reader = NULL;
|
||||||
FAR struct list_node *node;
|
|
||||||
pollevent_t eventset;
|
pollevent_t eventset;
|
||||||
int ndx;
|
int ndx;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -1042,16 +1035,8 @@ static int can_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_for_every(&dev->cd_readers, node)
|
DEBUGASSERT(filep->f_priv != NULL);
|
||||||
{
|
reader = (FAR struct can_reader_s *)filep->f_priv;
|
||||||
if (((FAR struct can_reader_s *)node)->filep == filep)
|
|
||||||
{
|
|
||||||
reader = (FAR struct can_reader_s *)node;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUGASSERT(reader != NULL);
|
|
||||||
|
|
||||||
/* Get exclusive access to the poll structures */
|
/* Get exclusive access to the poll structures */
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -561,7 +561,6 @@ struct can_reader_s
|
|||||||
{
|
{
|
||||||
struct list_node list;
|
struct list_node list;
|
||||||
sem_t read_sem;
|
sem_t read_sem;
|
||||||
FAR struct file *filep;
|
|
||||||
struct can_rxfifo_s fifo; /* Describes receive FIFO */
|
struct can_rxfifo_s fifo; /* Describes receive FIFO */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -590,6 +589,7 @@ struct can_dev_s
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Structures used with ioctl calls */
|
/* Structures used with ioctl calls */
|
||||||
|
|
||||||
/* CANIOC_RTR: */
|
/* CANIOC_RTR: */
|
||||||
|
|
||||||
struct canioc_rtr_s
|
struct canioc_rtr_s
|
||||||
@@ -598,8 +598,9 @@ struct canioc_rtr_s
|
|||||||
FAR struct can_msg_s *ci_msg; /* The location to return the RTR response */
|
FAR struct can_msg_s *ci_msg; /* The location to return the RTR response */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CANIOC_GET_BITTIMING/CANIOC_SET_BITTIMING: */
|
/* CANIOC_GET_BITTIMING/CANIOC_SET_BITTIMING:
|
||||||
/* Bit time = Tquanta * (Sync_Seg + Prop_Seq + Phase_Seg1 + Phase_Seg2)
|
*
|
||||||
|
* Bit time = Tquanta * (Sync_Seg + Prop_Seq + Phase_Seg1 + Phase_Seg2)
|
||||||
* = Tquanta * (TSEG1 + TSEG2 + 1)
|
* = Tquanta * (TSEG1 + TSEG2 + 1)
|
||||||
* Where
|
* Where
|
||||||
* TSEG1 = Prop_Seq + Phase_Seg1
|
* TSEG1 = Prop_Seq + Phase_Seg1
|
||||||
@@ -614,8 +615,9 @@ struct canioc_bittiming_s
|
|||||||
uint8_t bt_sjw; /* Synchronization Jump Width in time quanta */
|
uint8_t bt_sjw; /* Synchronization Jump Width in time quanta */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CANIOC_GET_CONNMODES/CANIOC_SET_CONNMODES: */
|
/* CANIOC_GET_CONNMODES/CANIOC_SET_CONNMODES:
|
||||||
/* A CAN device may support loopback and silent mode. Both modes may not be
|
*
|
||||||
|
* A CAN device may support loopback and silent mode. Both modes may not be
|
||||||
* settable independently.
|
* settable independently.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -654,11 +656,7 @@ struct canioc_stdfilter_s
|
|||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Public Data
|
* Public Function Prototypes
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
|||||||
Reference in New Issue
Block a user