Skip to content
Snippets Groups Projects
Commit 881e935a authored by Florian Pose's avatar Florian Pose
Browse files

Allow only one open() on XML device.

parent 6b12229e
No related branches found
No related tags found
No related merge requests found
...@@ -74,6 +74,7 @@ int ec_xmldev_init(ec_xmldev_t *xmldev, /**< EtherCAT XML device */ ...@@ -74,6 +74,7 @@ int ec_xmldev_init(ec_xmldev_t *xmldev, /**< EtherCAT XML device */
dev_t dev_num /**< device number */ dev_t dev_num /**< device number */
) )
{ {
atomic_set(&xmldev->available, 1);
cdev_init(&xmldev->cdev, &fops); cdev_init(&xmldev->cdev, &fops);
xmldev->cdev.owner = THIS_MODULE; xmldev->cdev.owner = THIS_MODULE;
if (cdev_add(&xmldev->cdev, if (cdev_add(&xmldev->cdev,
...@@ -97,11 +98,29 @@ void ec_xmldev_clear(ec_xmldev_t *xmldev /**< EtherCAT XML device */) ...@@ -97,11 +98,29 @@ void ec_xmldev_clear(ec_xmldev_t *xmldev /**< EtherCAT XML device */)
/*****************************************************************************/ /*****************************************************************************/
int ec_xmldev_request(ec_xmldev_t *xmldev,
uint32_t vendor_id,
uint32_t product_code
)
{
return 1;
}
/******************************************************************************
* file_operations
*****************************************************************************/
int ecxmldev_open(struct inode *inode, struct file *filp) int ecxmldev_open(struct inode *inode, struct file *filp)
{ {
ec_xmldev_t *xmldev; ec_xmldev_t *xmldev;
xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev);
if (!atomic_dec_and_test(&xmldev->available)) {
atomic_inc(&xmldev->available);
return -EBUSY;
}
filp->private_data = xmldev; filp->private_data = xmldev;
EC_DBG("File opened.\n"); EC_DBG("File opened.\n");
...@@ -113,6 +132,8 @@ int ecxmldev_open(struct inode *inode, struct file *filp) ...@@ -113,6 +132,8 @@ int ecxmldev_open(struct inode *inode, struct file *filp)
int ecxmldev_release(struct inode *inode, struct file *filp) int ecxmldev_release(struct inode *inode, struct file *filp)
{ {
ec_xmldev_t *xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev);
atomic_inc(&xmldev->available);
EC_DBG("File closed.\n"); EC_DBG("File closed.\n");
return 0; return 0;
} }
......
...@@ -57,6 +57,7 @@ typedef struct ...@@ -57,6 +57,7 @@ typedef struct
{ {
ec_master_t *master; /**< master owning the device */ ec_master_t *master; /**< master owning the device */
struct cdev cdev; /**< character device */ struct cdev cdev; /**< character device */
atomic_t available; /**< allow only one open() */
} }
ec_xmldev_t; ec_xmldev_t;
...@@ -65,6 +66,8 @@ ec_xmldev_t; ...@@ -65,6 +66,8 @@ ec_xmldev_t;
int ec_xmldev_init(ec_xmldev_t *, ec_master_t *, dev_t); int ec_xmldev_init(ec_xmldev_t *, ec_master_t *, dev_t);
void ec_xmldev_clear(ec_xmldev_t *); void ec_xmldev_clear(ec_xmldev_t *);
int ec_xmldev_request(ec_xmldev_t *, uint32_t, uint32_t);
/*****************************************************************************/ /*****************************************************************************/
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment