[PATCH 11/11] staging: dgnc: introduce find_board_by_major()

2016-09-21 Thread Daeseok Youn
It was used to get a board structure with dgnc_BoardsByMajor array.
But this driver already has the array for managing initialized board
as dgap_board[]. It can be used for searching the board structure
by major number.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_tty.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index ba724ab..a486a86 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -45,7 +45,6 @@
 /*
  * internal variables
  */
-static struct dgnc_board   *dgnc_BoardsByMajor[256];
 static unsigned char   *dgnc_TmpWriteBuf;
 
 /*
@@ -251,8 +250,6 @@ int dgnc_tty_register(struct dgnc_board *brd)
goto free_print_driver;
}
 
-   dgnc_BoardsByMajor[brd->serial_driver->major] = brd;
-
return 0;
 
 free_print_driver:
@@ -388,7 +385,6 @@ void dgnc_cleanup_tty(struct dgnc_board *brd)
 {
int i = 0;
 
-   dgnc_BoardsByMajor[brd->serial_driver->major] = NULL;
for (i = 0; i < brd->nasync; i++) {
if (brd->channels[i])
dgnc_remove_tty_sysfs(brd->channels[i]->
@@ -397,7 +393,6 @@ void dgnc_cleanup_tty(struct dgnc_board *brd)
}
tty_unregister_driver(brd->serial_driver);
 
-   dgnc_BoardsByMajor[brd->print_driver->major] = NULL;
for (i = 0; i < brd->nasync; i++) {
if (brd->channels[i])
dgnc_remove_tty_sysfs(brd->channels[i]->
@@ -935,6 +930,24 @@ void dgnc_wakeup_writes(struct channel_t *ch)
spin_unlock_irqrestore(>ch_lock, flags);
 }
 
+struct dgnc_board *find_board_by_major(unsigned int major)
+{
+   int i;
+
+   for (i = 0; i < MAXBOARDS; i++) {
+   struct dgnc_board *brd = dgnc_board[i];
+
+   if (!brd)
+   return NULL;
+
+   if (major == brd->serial_driver->major ||
+   major == brd->print_driver->major)
+   return brd;
+   }
+
+   return NULL;
+}
+
 /
  *
  * TTY Entry points and helper functions
@@ -964,7 +977,7 @@ static int dgnc_tty_open(struct tty_struct *tty, struct 
file *file)
return -ENXIO;
 
/* Get board pointer from our array of majors we have allocated */
-   brd = dgnc_BoardsByMajor[major];
+   brd = find_board_by_major(major);
if (!brd)
return -ENXIO;
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/11] staging: dgnc: remove useless variables

2016-09-21 Thread Daeseok Youn
The dgnc_major_serial_registered and dgnc_major_serial_registered
do not need to use to check whether the tty driver is registered or not.
These variables are used only in dgnc_cleanup_tty() function,
This function will be called normally with initialized board structure.
It means the dgnc_cleanup_tty() cannot be called with unregistered tty.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.h |  3 --
 drivers/staging/dgnc/dgnc_tty.c| 64 +++---
 2 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.h 
b/drivers/staging/dgnc/dgnc_driver.h
index 747a100..8792026 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -203,9 +203,6 @@ struct dgnc_board {
struct tty_driver *print_driver;
charprint_name[200];
 
-   booldgnc_major_serial_registered;
-   booldgnc_major_transparent_print_registered;
-
u16 dpatype;/* The board "type",
 * as defined by DPA
 */
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 5befd28..ba724ab 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -204,15 +204,11 @@ int dgnc_tty_register(struct dgnc_board *brd)
 */
tty_set_operations(brd->serial_driver, _tty_ops);
 
-   if (!brd->dgnc_major_serial_registered) {
-   /* Register tty devices */
-   rc = tty_register_driver(brd->serial_driver);
-   if (rc < 0) {
-   dev_dbg(>pdev->dev,
-   "Can't register tty device (%d)\n", rc);
-   goto free_serial_driver;
-   }
-   brd->dgnc_major_serial_registered = true;
+   rc = tty_register_driver(brd->serial_driver);
+   if (rc < 0) {
+   dev_dbg(>pdev->dev,
+   "Can't register tty device (%d)\n", rc);
+   goto free_serial_driver;
}
 
/*
@@ -247,16 +243,12 @@ int dgnc_tty_register(struct dgnc_board *brd)
 */
tty_set_operations(brd->print_driver, _tty_ops);
 
-   if (!brd->dgnc_major_transparent_print_registered) {
-   /* Register Transparent Print devices */
-   rc = tty_register_driver(brd->print_driver);
-   if (rc < 0) {
-   dev_dbg(>pdev->dev,
-   "Can't register Transparent Print device(%d)\n",
-   rc);
-   goto free_print_driver;
-   }
-   brd->dgnc_major_transparent_print_registered = true;
+   rc = tty_register_driver(brd->print_driver);
+   if (rc < 0) {
+   dev_dbg(>pdev->dev,
+   "Can't register Transparent Print device(%d)\n",
+   rc);
+   goto free_print_driver;
}
 
dgnc_BoardsByMajor[brd->serial_driver->major] = brd;
@@ -396,29 +388,23 @@ void dgnc_cleanup_tty(struct dgnc_board *brd)
 {
int i = 0;
 
-   if (brd->dgnc_major_serial_registered) {
-   dgnc_BoardsByMajor[brd->serial_driver->major] = NULL;
-   for (i = 0; i < brd->nasync; i++) {
-   if (brd->channels[i])
-   dgnc_remove_tty_sysfs(brd->channels[i]->
- ch_tun.un_sysfs);
-   tty_unregister_device(brd->serial_driver, i);
-   }
-   tty_unregister_driver(brd->serial_driver);
-   brd->dgnc_major_serial_registered = false;
+   dgnc_BoardsByMajor[brd->serial_driver->major] = NULL;
+   for (i = 0; i < brd->nasync; i++) {
+   if (brd->channels[i])
+   dgnc_remove_tty_sysfs(brd->channels[i]->
+ ch_tun.un_sysfs);
+   tty_unregister_device(brd->serial_driver, i);
}
+   tty_unregister_driver(brd->serial_driver);
 
-   if (brd->dgnc_major_transparent_print_registered) {
-   dgnc_BoardsByMajor[brd->print_driver->major] = NULL;
-   for (i = 0; i < brd->nasync; i++) {
-   if (brd->channels[i])
-   dgnc_remove_tty_sysfs(brd->channels[i]->
- ch_pun.un_sysfs);
-   tty_unregister_device(brd->print_driver, i);
-   }
-   tty_unregister_driver(brd->print_driver);
-   brd->dgnc_major_transparent_print_registered = false;
+   dgnc_BoardsByMajor[brd->print_driver->major] = NULL;
+   for (i = 0; i < brd->nasync; i++) {
+   if (brd->channels[i])
+   

[PATCH 09/11] staging: dgnc: rename dgnc_tty_uninit() to

2016-09-21 Thread Daeseok Youn
The dgnc_tty_uninit() doesn't match with dgnc_tty_init() at all.
And also the dgnc_cleanup_tty() is only called for exiting the module.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 2 +-
 drivers/staging/dgnc/dgnc_tty.c| 4 ++--
 drivers/staging/dgnc/dgnc_tty.h| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 81ce5c4..fd372d3 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -147,7 +147,7 @@ static void cleanup(bool sysfiles)
 
for (i = 0; i < dgnc_num_boards; ++i) {
dgnc_remove_ports_sysfiles(dgnc_board[i]);
-   dgnc_tty_uninit(dgnc_board[i]);
+   dgnc_cleanup_tty(dgnc_board[i]);
dgnc_cleanup_board(dgnc_board[i]);
}
 
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 893f473..5befd28 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -387,12 +387,12 @@ void dgnc_tty_post_uninit(void)
 }
 
 /*
- * dgnc_tty_uninit()
+ * dgnc_cleanup_tty()
  *
  * Uninitialize the TTY portion of this driver.  Free all memory and
  * resources.
  */
-void dgnc_tty_uninit(struct dgnc_board *brd)
+void dgnc_cleanup_tty(struct dgnc_board *brd)
 {
int i = 0;
 
diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
index f065c8f..24c9a41 100644
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ b/drivers/staging/dgnc/dgnc_tty.h
@@ -25,7 +25,7 @@ int   dgnc_tty_preinit(void);
 int dgnc_tty_init(struct dgnc_board *);
 
 void   dgnc_tty_post_uninit(void);
-void   dgnc_tty_uninit(struct dgnc_board *);
+void   dgnc_cleanup_tty(struct dgnc_board *);
 
 void   dgnc_input(struct channel_t *ch);
 void   dgnc_carrier(struct channel_t *ch);
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/11] staging: dgnc: introduce the dgnc_free_irq()

2016-09-21 Thread Daeseok Youn
The dgnc_free_irq() will free the requested IRQ from
the dgnc_request_irq().

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 70e68b5..81ce5c4 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -38,6 +38,7 @@ MODULE_SUPPORTED_DEVICE("dgnc");
  */
 static int dgnc_start(void);
 static int dgnc_request_irq(struct dgnc_board *brd);
+static void dgnc_free_irq(struct dgnc_board *brd);
 static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id);
 static voiddgnc_cleanup_board(struct dgnc_board *brd);
 static voiddgnc_poll_handler(ulong dummy);
@@ -305,7 +306,7 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
rc = dgnc_tty_init(brd);
if (rc < 0) {
pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
-   goto unregister_tty;
+   goto free_irq;
}
 
brd->state = BOARD_READY;
@@ -317,6 +318,8 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
return 0;
 
+free_irq:
+   dgnc_free_irq(brd);
 unregister_tty:
dgnc_tty_unregister(brd);
 
@@ -577,6 +580,12 @@ static int dgnc_request_irq(struct dgnc_board *brd)
return rc;
 }
 
+static void dgnc_free_irq(struct dgnc_board *brd)
+{
+   if (brd->irq)
+   free_irq(brd->irq, brd);
+}
+
 /*
  * Remap PCI memory.
  */
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/11] staging: dgnc: rename dgnc_finalize_board_init() to

2016-09-21 Thread Daeseok Youn
The dgnc_finalize_board_init() function has only job for
requesting the IRQ. It should be renamed to dgnc_request_irq()

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index ffe55a2..70e68b5 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -37,7 +37,7 @@ MODULE_SUPPORTED_DEVICE("dgnc");
  *
  */
 static int dgnc_start(void);
-static int dgnc_finalize_board_init(struct dgnc_board *brd);
+static int dgnc_request_irq(struct dgnc_board *brd);
 static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id);
 static voiddgnc_cleanup_board(struct dgnc_board *brd);
 static voiddgnc_poll_handler(ulong dummy);
@@ -296,7 +296,7 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
goto failed;
}
 
-   rc = dgnc_finalize_board_init(brd);
+   rc = dgnc_request_irq(brd);
if (rc < 0) {
pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
goto unregister_tty;
@@ -558,7 +558,7 @@ failed:
return ERR_PTR(rc);
 }
 
-static int dgnc_finalize_board_init(struct dgnc_board *brd)
+static int dgnc_request_irq(struct dgnc_board *brd)
 {
int rc = 0;
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/11] staging: dgnc: introduce the dgnc_tty_unregister()

2016-09-21 Thread Daeseok Youn
The dgnc_tty_unregister() will be called when
the dgnc_tty_register() is failed.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 7 +--
 drivers/staging/dgnc/dgnc_tty.c| 8 
 drivers/staging/dgnc/dgnc_tty.h| 1 +
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index a95d13c..ffe55a2 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -299,13 +299,13 @@ static int dgnc_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
rc = dgnc_finalize_board_init(brd);
if (rc < 0) {
pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
-   goto failed;
+   goto unregister_tty;
}
 
rc = dgnc_tty_init(brd);
if (rc < 0) {
pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
-   goto failed;
+   goto unregister_tty;
}
 
brd->state = BOARD_READY;
@@ -317,6 +317,9 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
return 0;
 
+unregister_tty:
+   dgnc_tty_unregister(brd);
+
 failed:
kfree(brd);
 
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index fd46ef0..893f473 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -273,6 +273,14 @@ free_serial_driver:
return rc;
 }
 
+void dgnc_tty_unregister(struct dgnc_board *brd)
+{
+   tty_unregister_driver(brd->print_driver);
+   tty_unregister_driver(brd->serial_driver);
+   put_tty_driver(brd->print_driver);
+   put_tty_driver(brd->serial_driver);
+}
+
 /*
  * dgnc_tty_init()
  *
diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
index 21d3369..f065c8f 100644
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ b/drivers/staging/dgnc/dgnc_tty.h
@@ -19,6 +19,7 @@
 #include "dgnc_driver.h"
 
 intdgnc_tty_register(struct dgnc_board *brd);
+void dgnc_tty_unregister(struct dgnc_board *brd);
 
 intdgnc_tty_preinit(void);
 int dgnc_tty_init(struct dgnc_board *);
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/11] staging: dgnc: move functions unrelated with

2016-09-21 Thread Daeseok Youn
The functions related with tty device initialization are needed
to be moved from dgnc_found_board() to dgnc_init_one().

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 81 --
 1 file changed, 43 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 0114e78..a95d13c 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -38,7 +38,7 @@ MODULE_SUPPORTED_DEVICE("dgnc");
  */
 static int dgnc_start(void);
 static int dgnc_finalize_board_init(struct dgnc_board *brd);
-static int dgnc_found_board(struct pci_dev *pdev, int id);
+static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id);
 static voiddgnc_cleanup_board(struct dgnc_board *brd);
 static voiddgnc_poll_handler(ulong dummy);
 static int dgnc_init_one(struct pci_dev *pdev,
@@ -274,6 +274,7 @@ failed_class:
 static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
int rc;
+   struct dgnc_board *brd;
 
/* wake up and enable device */
rc = pci_enable_device(pdev);
@@ -281,9 +282,43 @@ static int dgnc_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
if (rc)
return -EIO;
 
-   rc = dgnc_found_board(pdev, ent->driver_data);
-   if (rc == 0)
-   dgnc_num_boards++;
+   brd = dgnc_found_board(pdev, ent->driver_data);
+   if (IS_ERR(brd))
+   return PTR_ERR(brd);
+
+   /*
+* Do tty device initialization.
+*/
+
+   rc = dgnc_tty_register(brd);
+   if (rc < 0) {
+   pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
+   goto failed;
+   }
+
+   rc = dgnc_finalize_board_init(brd);
+   if (rc < 0) {
+   pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
+   goto failed;
+   }
+
+   rc = dgnc_tty_init(brd);
+   if (rc < 0) {
+   pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
+   goto failed;
+   }
+
+   brd->state = BOARD_READY;
+   brd->dpastatus = BD_RUNNING;
+
+   dgnc_create_ports_sysfiles(brd);
+
+   dgnc_board[dgnc_num_boards++] = brd;
+
+   return 0;
+
+failed:
+   kfree(brd);
 
return rc;
 }
@@ -345,7 +380,7 @@ static void dgnc_cleanup_board(struct dgnc_board *brd)
  *
  * A board has been found, init it.
  */
-static int dgnc_found_board(struct pci_dev *pdev, int id)
+static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
 {
struct dgnc_board *brd;
unsigned int pci_irq;
@@ -355,7 +390,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
/* get the board structure and prep it */
brd = kzalloc(sizeof(*brd), GFP_KERNEL);
if (!brd)
-   return -ENOMEM;
+   return ERR_PTR(-ENOMEM);
 
/* store the info for the board we've found */
brd->magic = DGNC_BOARD_MAGIC;
@@ -505,33 +540,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
goto failed;
}
 
-   /*
-* Do tty device initialization.
-*/
-
-   rc = dgnc_tty_register(brd);
-   if (rc < 0) {
-   pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
-   goto failed;
-   }
-
-   rc = dgnc_finalize_board_init(brd);
-   if (rc < 0) {
-   pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
-   goto failed;
-   }
-
-   rc = dgnc_tty_init(brd);
-   if (rc < 0) {
-   pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
-   goto failed;
-   }
-
-   brd->state = BOARD_READY;
-   brd->dpastatus = BD_RUNNING;
-
-   dgnc_create_ports_sysfiles(brd);
-
/* init our poll helper tasklet */
tasklet_init(>helper_tasklet,
 brd->bd_ops->tasklet,
@@ -539,15 +547,12 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
wake_up_interruptible(>state_wait);
 
-   dgnc_board[dgnc_num_boards] = brd;
-
-   return 0;
+   return brd;
 
 failed:
-   dgnc_tty_uninit(brd);
kfree(brd);
 
-   return rc;
+   return ERR_PTR(rc);
 }
 
 static int dgnc_finalize_board_init(struct dgnc_board *brd)
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/11] staging: dgnc: missing NULL check for ioremap in

2016-09-21 Thread Daeseok Youn
The ioremap() function can be failed, so it need to have error
handling in dgnc_do_remap(). And also the return type of
dgnc_do_remap() should be changed from "void" to "int"

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 31 +--
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index c87b3de..58cebf4 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -43,7 +43,7 @@ static void   dgnc_cleanup_board(struct dgnc_board 
*brd);
 static voiddgnc_poll_handler(ulong dummy);
 static int dgnc_init_one(struct pci_dev *pdev,
  const struct pci_device_id *ent);
-static voiddgnc_do_remap(struct dgnc_board *brd);
+static int dgnc_do_remap(struct dgnc_board *brd);
 
 /*
  * File operations permitted on Control/Management major.
@@ -431,7 +431,10 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
brd->bd_uart_offset = 0x8;
brd->bd_dividend = 921600;
 
-   dgnc_do_remap(brd);
+   rc = dgnc_do_remap(brd);
+
+   if (rc < 0)
+   goto failed;
 
/* Get and store the board VPD, if it exists */
brd->bd_ops->vpd(brd);
@@ -483,15 +486,17 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
brd->bd_uart_offset = 0x200;
brd->bd_dividend = 921600;
 
-   dgnc_do_remap(brd);
+   rc = dgnc_do_remap(brd);
 
-   if (brd->re_map_membase) {
-   /* Read and store the dvid after remapping */
-   brd->dvid = readb(brd->re_map_membase + 0x8D);
+   if (rc < 0)
+   goto failed;
+
+   /* Read and store the dvid after remapping */
+   brd->dvid = readb(brd->re_map_membase + 0x8D);
+
+   /* Get and store the board VPD, if it exists */
+   brd->bd_ops->vpd(brd);
 
-   /* Get and store the board VPD, if it exists */
-   brd->bd_ops->vpd(brd);
-   }
break;
 
default:
@@ -566,9 +571,15 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
 /*
  * Remap PCI memory.
  */
-static void dgnc_do_remap(struct dgnc_board *brd)
+static int dgnc_do_remap(struct dgnc_board *brd)
 {
+   int rc = 0;
+
brd->re_map_membase = ioremap(brd->membase, 0x1000);
+   if (!brd->re_map_membase)
+   rc = -ENOMEM;
+
+   return rc;
 }
 
 /*
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/11] staging: dgnc: kfree for board structure in

2016-09-21 Thread Daeseok Youn
The board structure should be freed when any function was failed
in dgnc_found_board(). And the board strucure will be stored
into dgnc_board array when the dgnc_found_board() function has no error.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 58cebf4..0114e78 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -353,9 +353,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
int rc = 0;
 
/* get the board structure and prep it */
-   dgnc_board[dgnc_num_boards] = kzalloc(sizeof(*brd), GFP_KERNEL);
-   brd = dgnc_board[dgnc_num_boards];
-
+   brd = kzalloc(sizeof(*brd), GFP_KERNEL);
if (!brd)
return -ENOMEM;
 
@@ -411,7 +409,8 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
if (!brd->membase) {
dev_err(>pdev->dev,
"Card has no PCI IO resources, failing.\n");
-   return -ENODEV;
+   rc = -ENODEV;
+   goto failed;
}
 
brd->membase_end = pci_resource_end(pdev, 4);
@@ -502,7 +501,8 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
default:
dev_err(>pdev->dev,
"Didn't find any compatible Neo/Classic PCI boards.\n");
-   return -ENXIO;
+   rc = -ENXIO;
+   goto failed;
}
 
/*
@@ -539,14 +539,15 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
wake_up_interruptible(>state_wait);
 
+   dgnc_board[dgnc_num_boards] = brd;
+
return 0;
 
 failed:
dgnc_tty_uninit(brd);
-   brd->state = BOARD_FAILED;
-   brd->dpastatus = BD_NOFEP;
+   kfree(brd);
 
-   return -ENXIO;
+   return rc;
 }
 
 static int dgnc_finalize_board_init(struct dgnc_board *brd)
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/11] staging: dgnc: remove redundant initialization for

2016-09-21 Thread Daeseok Youn
The channel array in board_t was initialized in dgnc_found_board()
with NULL. But the channel is going to initialize in dgnc_tty_init().
So the channel array doesn't need to set NULL for initailization.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 01e948c..b598034 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -400,9 +400,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
brd->state  = BOARD_FOUND;
 
-   for (i = 0; i < MAXPORTS; i++)
-   brd->channels[i] = NULL;
-
/* store which card & revision we have */
pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, >subvendor);
pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, >subdevice);
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/11] staging: dgnc: remove useless message buffer

2016-09-21 Thread Daeseok Youn
There is a temporary message buffer for the boot message
in dgnc_found_board() but the buffer was not used anywhere in
dgnc driver.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 28 
 drivers/staging/dgnc/dgnc_driver.h |  6 --
 2 files changed, 34 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index b598034..c87b3de 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -324,17 +324,6 @@ static void dgnc_cleanup_board(struct dgnc_board *brd)
brd->re_map_membase = NULL;
}
 
-   if (brd->msgbuf_head) {
-   unsigned long flags;
-
-   spin_lock_irqsave(_global_lock, flags);
-   brd->msgbuf = NULL;
-   dev_dbg(>pdev->dev, "%s\n", brd->msgbuf_head);
-   kfree(brd->msgbuf_head);
-   brd->msgbuf_head = NULL;
-   spin_unlock_irqrestore(_global_lock, flags);
-   }
-
/* Free all allocated channels structs */
for (i = 0; i < MAXPORTS ; i++) {
if (brd->channels[i]) {
@@ -362,7 +351,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
unsigned int pci_irq;
int i = 0;
int rc = 0;
-   unsigned long flags;
 
/* get the board structure and prep it */
dgnc_board[dgnc_num_boards] = kzalloc(sizeof(*brd), GFP_KERNEL);
@@ -371,15 +359,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
if (!brd)
return -ENOMEM;
 
-   /* make a temporary message buffer for the boot messages */
-   brd->msgbuf_head = kcalloc(8192, sizeof(u8), GFP_KERNEL);
-   brd->msgbuf = brd->msgbuf_head;
-
-   if (!brd->msgbuf) {
-   kfree(brd);
-   return -ENOMEM;
-   }
-
/* store the info for the board we've found */
brd->magic = DGNC_BOARD_MAGIC;
brd->boardnum = dgnc_num_boards;
@@ -553,13 +532,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 brd->bd_ops->tasklet,
 (unsigned long)brd);
 
-   spin_lock_irqsave(_global_lock, flags);
-   brd->msgbuf = NULL;
-   dev_dbg(>pdev->dev, "%s\n", brd->msgbuf_head);
-   kfree(brd->msgbuf_head);
-   brd->msgbuf_head = NULL;
-   spin_unlock_irqrestore(_global_lock, flags);
-
wake_up_interruptible(>state_wait);
 
return 0;
diff --git a/drivers/staging/dgnc/dgnc_driver.h 
b/drivers/staging/dgnc/dgnc_driver.h
index 88d2696..747a100 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -213,12 +213,6 @@ struct dgnc_board {
 * as defined by DPA
 */
 
-   /*
-*  Mgmt data.
-*/
-   char*msgbuf_head;
-   char*msgbuf;
-
uintbd_dividend;/* Board/UARTs specific dividend */
 
struct board_ops *bd_ops;
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 00/11] staging: dgnc: cleanup the function on dgnc driver

2016-09-21 Thread Daeseok Youn
This series of patches will cleanup the functions in dgnc driver.
Rename it and introduce new functions to split big function into
smaller one. Please take a look at my patches to update the dgnc
driver and provide some comments if there are something wrong.

This series of patches maybe have dependency with each other.
If one of these patches cannot be merged, some other patches maybe
cannot be merged properly, I think.

Daeseok Youn (11):
  staging: dgnc: remove redundant initialization for channel_t
  staging: dgnc: remove useless message buffer
  staging: dgnc: missing NULL check for ioremap in dgnc_do_remap()
  staging: dgnc: kfree for board structure in dgnc_found_board()
  staging: dgnc: move functions unrelated with dgnc_found_board()
  staging: dgnc: introduce the dgnc_tty_unregister()
  staging: dgnc: rename dgnc_finalize_board_init() to dgnc_request_irq()
  staging: dgnc: introduce the dgnc_free_irq()
  staging: dgnc: rename dgnc_tty_uninit() to dgnc_cleanup_tty()
  staging: dgnc: remove useless variables
  staging: dgnc: introduce find_board_by_major()

 drivers/staging/dgnc/dgnc_driver.c | 170 ++---
 drivers/staging/dgnc/dgnc_driver.h |   9 --
 drivers/staging/dgnc/dgnc_tty.c|  97 +++--
 drivers/staging/dgnc/dgnc_tty.h|   3 +-
 4 files changed, 138 insertions(+), 141 deletions(-)

-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] rtl871x: use tabs with indentation instead of spaces

2016-09-21 Thread Christopher Pezley
There is a line with space indentation instead of tabs. I've changed it to use 
tabs for indentation.

Signed-off-by: Christopher H. Pezley 
---
drivers/staging/rtl8712/rtl871x_ioctl_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c 
b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index e205adf..df985ce 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1976,7 +1976,7 @@ static int r871x_get_ap_info(struct net_device *dev,
if (pdata->length >= 32) {
if (copy_from_user(data, pdata->pointer, 32))
return -EINVAL;
-data[32] = 0;
+   data[32] = 0;
} else {
 return -EINVAL;
}
--
2.7.4
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/2] staging: greybus: audio_codec.c: code indent should use tabs where possible

2016-09-21 Thread Alex Elder
On 09/21/2016 12:05 PM, Richard Groux wrote:
> Minor error spotted by checkpatch.pl in greybus
> code indent should use tabs where possible
> 
> Signed-off-by: Richard Groux 

Looks good.

Reviewed-by: Alex Elder 

> ---
>  drivers/staging/greybus/audio_codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/greybus/audio_codec.c 
> b/drivers/staging/greybus/audio_codec.c
> index f347743..a46ca42 100644
> --- a/drivers/staging/greybus/audio_codec.c
> +++ b/drivers/staging/greybus/audio_codec.c
> @@ -1008,7 +1008,7 @@ static int gbcodec_probe(struct snd_soc_codec *codec)
>   snd_soc_codec_set_drvdata(codec, info);
>   gbcodec = info;
>  
> -device_init_wakeup(codec->dev, 1);
> + device_init_wakeup(codec->dev, 1);
>   return 0;
>  }
>  
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: greybus: audio_codec.c: space required before the open brace

2016-09-21 Thread Alex Elder
On 09/21/2016 12:05 PM, Richard Groux wrote:
> Minor error spotted by checkpatch.pl in greybus
> space required before the open brace '{'
> 
> Signed-off-by: Richard Groux 

Sure, looks good.  Greg will have to apply these patches.

Reviewed-by: Alex Elder 


> ---
>  drivers/staging/greybus/audio_codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/greybus/audio_codec.c 
> b/drivers/staging/greybus/audio_codec.c
> index 2f70295..f347743 100644
> --- a/drivers/staging/greybus/audio_codec.c
> +++ b/drivers/staging/greybus/audio_codec.c
> @@ -322,7 +322,7 @@ int gbaudio_module_update(struct gbaudio_codec_info 
> *codec,
>   dev_dbg(module->dev, "%s:Module update %s sequence\n", w->name,
>   enable ? "Enable":"Disable");
>  
> - if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)){
> + if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)) {
>   dev_dbg(codec->dev, "No action required for %s\n", w->name);
>   return 0;
>   }
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 7/7] selftest: sync: stress test for merges

2016-09-21 Thread Emilio López
This test is based on the libsync test suite from Android.
This commit includes a test to stress merge operations.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile|   1 +
 tools/testing/selftests/sync/sync_stress_merge.c | 116 +++
 tools/testing/selftests/sync/sync_test.c |   1 +
 tools/testing/selftests/sync/synctest.h  |   3 +
 4 files changed, 121 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index 910e3f9..6e05749 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -20,6 +20,7 @@ TESTS += sync_merge.o
 TESTS += sync_wait.o
 TESTS += sync_stress_parallelism.o
 TESTS += sync_stress_consumer.o
+TESTS += sync_stress_merge.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_merge.c 
b/tools/testing/selftests/sync/sync_stress_merge.c
new file mode 100644
index 000..0e57360
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_merge.c
@@ -0,0 +1,116 @@
+/*
+ *  sync stress test: merging
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+static int fence_map[1024 * 32];
+
+int test_merge_stress_random_merge(void)
+{
+   int i, size, ret;
+   int timeline_count = 32;
+   int merge_count = 1024 * 32;
+   int timelines[timeline_count];
+   int fence, tmpfence, merged, valid;
+   int timeline, timeline_offset, sync_point;
+
+   srand(time(NULL));
+
+   for (i = 0; i < timeline_count; i++)
+   timelines[i] = sw_sync_timeline_create();
+
+   fence = sw_sync_fence_create(timelines[0], "fence", 0);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure creating fence\n");
+
+   memset(fence_map, -1, sizeof(fence_map));
+   fence_map[0] = 0;
+
+   /*
+* Randomly create sync_points out of a fixed set of timelines,
+* and merge them together
+*/
+   for (i = 0; i < merge_count; i++) {
+   /* Generate sync_point. */
+   timeline_offset = rand() % timeline_count;
+   timeline = timelines[timeline_offset];
+   sync_point = rand();
+
+   /* Keep track of the latest sync_point in each timeline. */
+   if (fence_map[timeline_offset] == -1)
+   fence_map[timeline_offset] = sync_point;
+   else if (fence_map[timeline_offset] < sync_point)
+   fence_map[timeline_offset] = sync_point;
+
+   /* Merge */
+   tmpfence = sw_sync_fence_create(timeline, "fence", sync_point);
+   merged = sync_merge("merge", tmpfence, fence);
+   sw_sync_fence_destroy(tmpfence);
+   sw_sync_fence_destroy(fence);
+   fence = merged;
+
+   valid = sw_sync_fence_is_valid(merged);
+   ASSERT(valid, "Failure creating fence i\n");
+   }
+
+   size = 0;
+   for (i = 0; i < timeline_count; i++)
+   if (fence_map[i] != -1)
+   size++;
+
+   /* Confirm our map matches the fence. */
+   ASSERT(sync_fence_size(fence) == size,
+  "Quantity of elements not matching\n");
+
+   /* Trigger the merged fence */
+   for (i = 0; i < timeline_count; i++) {
+   if (fence_map[i] != -1) {
+   ret = sync_wait(fence, 0);
+   ASSERT(ret == 0,
+  "Failure waiting on fence until timeout\n");
+   

[PATCH 5/7] selftest: sync: stress test for parallelism

2016-09-21 Thread Emilio López
This test is based on the libsync test suite from Android.
This commit includes a stress test that invokes operations
in parallel.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile  |   1 +
 .../selftests/sync/sync_stress_parallelism.c   | 111 +
 tools/testing/selftests/sync/sync_test.c   |   1 +
 tools/testing/selftests/sync/synctest.h|   3 +
 4 files changed, 116 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index 19731b9..1ed2864 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -18,6 +18,7 @@ TESTS += sync_alloc.o
 TESTS += sync_fence.o
 TESTS += sync_merge.o
 TESTS += sync_wait.o
+TESTS += sync_stress_parallelism.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_parallelism.c 
b/tools/testing/selftests/sync/sync_stress_parallelism.c
new file mode 100644
index 000..e6c9be6
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_parallelism.c
@@ -0,0 +1,111 @@
+/*
+ *  sync stress test: parallelism
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include 
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+static struct {
+   int iterations;
+   int timeline;
+   int counter;
+} test_data_two_threads;
+
+static int test_stress_two_threads_shared_timeline_thread(void *d)
+{
+   int thread_id = (long)d;
+   int timeline = test_data_two_threads.timeline;
+   int iterations = test_data_two_threads.iterations;
+   int fence, valid, ret, i;
+
+   for (i = 0; i < iterations; i++) {
+   fence = sw_sync_fence_create(timeline, "fence",
+i * 2 + thread_id);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure allocating fence\n");
+
+   /* Wait on the prior thread to complete */
+   ret = sync_wait(fence, -1);
+   ASSERT(ret > 0, "Problem occurred on prior thread\n");
+
+   /*
+* Confirm the previous thread's writes are visible
+* and then increment
+*/
+   ASSERT(test_data_two_threads.counter == i * 2 + thread_id,
+  "Counter got damaged!\n");
+   test_data_two_threads.counter++;
+
+   /* Kick off the other thread */
+   ret = sw_sync_timeline_inc(timeline, 1);
+   ASSERT(ret == 0, "Advancing timeline failed\n");
+
+   sw_sync_fence_destroy(fence);
+   }
+
+   return 0;
+}
+
+int test_stress_two_threads_shared_timeline(void)
+{
+   pthread_t a, b;
+   int valid;
+   int timeline = sw_sync_timeline_create();
+
+   valid = sw_sync_timeline_is_valid(timeline);
+   ASSERT(valid, "Failure allocating timeline\n");
+
+   test_data_two_threads.iterations = 1 << 16;
+   test_data_two_threads.counter = 0;
+   test_data_two_threads.timeline = timeline;
+
+   /*
+* Use a single timeline to synchronize two threads
+* hammmering on the same counter.
+*/
+
+   pthread_create(, NULL, (void *(*)(void *))
+  test_stress_two_threads_shared_timeline_thread,
+  (void *)0);
+   pthread_create(, NULL, (void *(*)(void *))
+  test_stress_two_threads_shared_timeline_thread,
+  (void *)1);
+
+   pthread_join(a, NULL);
+   pthread_join(b, NULL);
+
+   /* make sure the threads did not trample on one another */
+   

[PATCH 6/7] selftest: sync: stress consumer/producer test

2016-09-21 Thread Emilio López
This test is based on the libsync test suite from Android.
This commit includes a stress test that replicates a
consumer/producer pattern.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile  |   1 +
 .../testing/selftests/sync/sync_stress_consumer.c  | 185 +
 tools/testing/selftests/sync/sync_test.c   |   1 +
 tools/testing/selftests/sync/synctest.h|   3 +
 4 files changed, 190 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index 1ed2864..910e3f9 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -19,6 +19,7 @@ TESTS += sync_fence.o
 TESTS += sync_merge.o
 TESTS += sync_wait.o
 TESTS += sync_stress_parallelism.o
+TESTS += sync_stress_consumer.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_stress_consumer.c 
b/tools/testing/selftests/sync/sync_stress_consumer.c
new file mode 100644
index 000..d9eff8d
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_stress_consumer.c
@@ -0,0 +1,185 @@
+/*
+ *  sync stress test: producer/consumer
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include 
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+/* IMPORTANT NOTE: if you see this test failing on your system, it may be
+ * due to a shortage of file descriptors. Please ensure your system has
+ * a sensible limit for this test to finish correctly.
+ */
+
+/* Returns 1 on error, 0 on success */
+static int busy_wait_on_fence(int fence)
+{
+   int error, active;
+
+   do {
+   error = sync_fence_count_with_status(fence, FENCE_STATUS_ERROR);
+   ASSERT(error == 0, "Error occurred on fence\n");
+   active = sync_fence_count_with_status(fence,
+ FENCE_STATUS_ACTIVE);
+   } while (active);
+
+   return 0;
+}
+
+static struct {
+   int iterations;
+   int threads;
+   int counter;
+   int consumer_timeline;
+   int *producer_timelines;
+   pthread_mutex_t lock;
+} test_data_mpsc;
+
+static int mpsc_producer_thread(void *d)
+{
+   int id = (long)d;
+   int fence, valid, i;
+   int *producer_timelines = test_data_mpsc.producer_timelines;
+   int consumer_timeline = test_data_mpsc.consumer_timeline;
+   int iterations = test_data_mpsc.iterations;
+
+   for (i = 0; i < iterations; i++) {
+   fence = sw_sync_fence_create(consumer_timeline, "fence", i);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure creating fence\n");
+
+   /*
+* Wait for the consumer to finish. Use alternate
+* means of waiting on the fence
+*/
+
+   if ((iterations + id) % 8 != 0) {
+   ASSERT(sync_wait(fence, -1) > 0,
+  "Failure waiting on fence\n");
+   } else {
+   ASSERT(busy_wait_on_fence(fence) == 0,
+  "Failure waiting on fence\n");
+   }
+
+   /*
+* Every producer increments the counter, the consumer
+* checks and erases it
+*/
+   pthread_mutex_lock(_data_mpsc.lock);
+   test_data_mpsc.counter++;
+   pthread_mutex_unlock(_data_mpsc.lock);
+
+   ASSERT(sw_sync_timeline_inc(producer_timelines[id], 1) == 0,
+  "Error advancing producer timeline\n");
+
+   sw_sync_fence_destroy(fence);
+  

[PATCH 4/7] selftest: sync: wait tests for sw_sync framework

2016-09-21 Thread Emilio López
These tests are based on the libsync test suite from Android.
This commit includes tests for waiting on fences.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile|  1 +
 tools/testing/selftests/sync/sync_test.c |  1 +
 tools/testing/selftests/sync/sync_wait.c | 91 
 tools/testing/selftests/sync/synctest.h  |  3 ++
 4 files changed, 96 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_wait.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index 53b716f..19731b9 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -17,6 +17,7 @@ SRC = sync_test.o sync.o
 TESTS += sync_alloc.o
 TESTS += sync_fence.o
 TESTS += sync_merge.o
+TESTS += sync_wait.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_test.c 
b/tools/testing/selftests/sync/sync_test.c
index ab37eee..eab5ceb 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -65,6 +65,7 @@ int main(void)
err += RUN_TEST(test_fence_one_timeline_wait);
err += RUN_TEST(test_fence_one_timeline_merge);
err += RUN_TEST(test_fence_merge_same_fence);
+   err += RUN_TEST(test_fence_multi_timeline_wait);
 
if (err)
printf("[FAIL]\tsync errors: %d\n", err);
diff --git a/tools/testing/selftests/sync/sync_wait.c 
b/tools/testing/selftests/sync/sync_wait.c
new file mode 100644
index 000..d69b752
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_wait.c
@@ -0,0 +1,91 @@
+/*
+ *  sync fence wait tests
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_multi_timeline_wait(void)
+{
+   int timelineA, timelineB, timelineC;
+   int fenceA, fenceB, fenceC, merged;
+   int valid, active, signaled, ret;
+
+   timelineA = sw_sync_timeline_create();
+   timelineB = sw_sync_timeline_create();
+   timelineC = sw_sync_timeline_create();
+
+   fenceA = sw_sync_fence_create(timelineA, "fenceA", 5);
+   fenceB = sw_sync_fence_create(timelineB, "fenceB", 5);
+   fenceC = sw_sync_fence_create(timelineC, "fenceC", 5);
+
+   merged = sync_merge("mergeFence", fenceB, fenceA);
+   merged = sync_merge("mergeFence", fenceC, merged);
+
+   valid = sw_sync_fence_is_valid(merged);
+   ASSERT(valid, "Failure merging fence from various timelines\n");
+
+   /* Confirm fence isn't signaled */
+   active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
+   ASSERT(active == 3, "Fence signaled too early!\n");
+
+   ret = sync_wait(merged, 0);
+   ASSERT(ret == 0,
+  "Failure waiting on fence until timeout\n");
+
+   ret = sw_sync_timeline_inc(timelineA, 5);
+   active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
+   signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
+   ASSERT(active == 2 && signaled == 1,
+  "Fence did not signal properly!\n");
+
+   ret = sw_sync_timeline_inc(timelineB, 5);
+   active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
+   signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
+   ASSERT(active == 1 && signaled == 2,
+  "Fence did not signal properly!\n");
+
+   ret = sw_sync_timeline_inc(timelineC, 5);
+   active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
+   signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
+   ASSERT(active == 0 && signaled == 3,
+  "Fence did not signal properly!\n");
+
+   /* 

[PATCH 3/7] selftest: sync: merge tests for sw_sync framework

2016-09-21 Thread Emilio López
These tests are based on the libsync test suite from Android.
This commit includes tests for basic merge operations.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile |  1 +
 tools/testing/selftests/sync/sync_merge.c | 60 +++
 tools/testing/selftests/sync/sync_test.c  |  1 +
 tools/testing/selftests/sync/synctest.h   |  3 ++
 4 files changed, 65 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_merge.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index 2bba52e..53b716f 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -16,6 +16,7 @@ SRC = sync_test.o sync.o
 
 TESTS += sync_alloc.o
 TESTS += sync_fence.o
+TESTS += sync_merge.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_merge.c 
b/tools/testing/selftests/sync/sync_merge.c
new file mode 100644
index 000..8914d43
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_merge.c
@@ -0,0 +1,60 @@
+/*
+ *  sync fence merge tests
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_merge_same_fence(void)
+{
+   int fence, valid, merged;
+   int timeline = sw_sync_timeline_create();
+
+   valid = sw_sync_timeline_is_valid(timeline);
+   ASSERT(valid, "Failure allocating timeline\n");
+
+   fence = sw_sync_fence_create(timeline, "allocFence", 5);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure allocating fence\n");
+
+   merged = sync_merge("mergeFence", fence, fence);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure merging fence\n");
+
+   ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 0,
+  "fence signaled too early!\n");
+
+   sw_sync_timeline_inc(timeline, 5);
+   ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 1,
+  "fence did not signal!\n");
+
+   sw_sync_fence_destroy(merged);
+   sw_sync_fence_destroy(fence);
+   sw_sync_timeline_destroy(timeline);
+
+   return 0;
+}
diff --git a/tools/testing/selftests/sync/sync_test.c 
b/tools/testing/selftests/sync/sync_test.c
index b442292b..ab37eee 100644
--- a/tools/testing/selftests/sync/sync_test.c
+++ b/tools/testing/selftests/sync/sync_test.c
@@ -64,6 +64,7 @@ int main(void)
 
err += RUN_TEST(test_fence_one_timeline_wait);
err += RUN_TEST(test_fence_one_timeline_merge);
+   err += RUN_TEST(test_fence_merge_same_fence);
 
if (err)
printf("[FAIL]\tsync errors: %d\n", err);
diff --git a/tools/testing/selftests/sync/synctest.h 
b/tools/testing/selftests/sync/synctest.h
index 6505c28..c3b0b5e 100644
--- a/tools/testing/selftests/sync/synctest.h
+++ b/tools/testing/selftests/sync/synctest.h
@@ -48,4 +48,7 @@ int test_alloc_fence_negative(void);
 int test_fence_one_timeline_wait(void);
 int test_fence_one_timeline_merge(void);
 
+/* Fence merge tests */
+int test_fence_merge_same_fence(void);
+
 #endif
-- 
2.9.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/7] selftest: sync: fence tests for sw_sync framework

2016-09-21 Thread Emilio López
These tests are based on the libsync test suite from Android.
This commit includes tests for basic fence creation.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/sync/Makefile |   1 +
 tools/testing/selftests/sync/sync_fence.c | 132 ++
 tools/testing/selftests/sync/sync_test.c  |   3 +
 tools/testing/selftests/sync/synctest.h   |   4 +
 4 files changed, 140 insertions(+)
 create mode 100644 tools/testing/selftests/sync/sync_fence.c

diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
index f67827f..2bba52e 100644
--- a/tools/testing/selftests/sync/Makefile
+++ b/tools/testing/selftests/sync/Makefile
@@ -15,6 +15,7 @@ include ../lib.mk
 SRC = sync_test.o sync.o
 
 TESTS += sync_alloc.o
+TESTS += sync_fence.o
 
 sync_test: $(SRC) $(TESTS)
 
diff --git a/tools/testing/selftests/sync/sync_fence.c 
b/tools/testing/selftests/sync/sync_fence.c
new file mode 100644
index 000..13f1752
--- /dev/null
+++ b/tools/testing/selftests/sync/sync_fence.c
@@ -0,0 +1,132 @@
+/*
+ *  sync fence tests with one timeline
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "sync.h"
+#include "sw_sync.h"
+#include "synctest.h"
+
+int test_fence_one_timeline_wait(void)
+{
+   int fence, valid, ret;
+   int timeline = sw_sync_timeline_create();
+
+   valid = sw_sync_timeline_is_valid(timeline);
+   ASSERT(valid, "Failure allocating timeline\n");
+
+   fence = sw_sync_fence_create(timeline, "allocFence", 5);
+   valid = sw_sync_fence_is_valid(fence);
+   ASSERT(valid, "Failure allocating fence\n");
+
+   /* Wait on fence until timeout */
+   ret = sync_wait(fence, 0);
+   ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
+
+   /* Advance timeline from 0 -> 1 */
+   ret = sw_sync_timeline_inc(timeline, 1);
+   ASSERT(ret == 0, "Failure advancing timeline\n");
+
+   /* Wait on fence until timeout */
+   ret = sync_wait(fence, 0);
+   ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
+
+   /* Signal the fence */
+   ret = sw_sync_timeline_inc(timeline, 4);
+   ASSERT(ret == 0, "Failure signaling the fence\n");
+
+   /* Wait successfully */
+   ret = sync_wait(fence, 0);
+   ASSERT(ret > 0, "Failure waiting on fence\n");
+
+   /* Go even further, and confirm wait still succeeds */
+   ret = sw_sync_timeline_inc(timeline, 10);
+   ASSERT(ret == 0, "Failure going further\n");
+   ret = sync_wait(fence, 0);
+   ASSERT(ret > 0, "Failure waiting ahead\n");
+
+   sw_sync_fence_destroy(fence);
+   sw_sync_timeline_destroy(timeline);
+
+   return 0;
+}
+
+int test_fence_one_timeline_merge(void)
+{
+   int a, b, c, d, valid;
+   int timeline = sw_sync_timeline_create();
+
+   /* create fence a,b,c and then merge them all into fence d */
+   a = sw_sync_fence_create(timeline, "allocFence", 1);
+   b = sw_sync_fence_create(timeline, "allocFence", 2);
+   c = sw_sync_fence_create(timeline, "allocFence", 3);
+
+   valid = sw_sync_fence_is_valid(a) &&
+   sw_sync_fence_is_valid(b) &&
+   sw_sync_fence_is_valid(c);
+   ASSERT(valid, "Failure allocating fences\n");
+
+   d = sync_merge("mergeFence", b, a);
+   d = sync_merge("mergeFence", c, d);
+   valid = sw_sync_fence_is_valid(d);
+   ASSERT(valid, "Failure merging fences\n");
+
+   /* confirm all fences have one active point (even d) */
+   ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+  "a has too many active fences!\n");
+   ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
+  "b has too many 

[PATCH 0/7] Tests for sync infrastructure

2016-09-21 Thread Emilio López
Hello everyone,

This is a series of tests to exercise the sync kernel infrastructure. It is
meant to be a test suite for the work Gustavo has been doing to destage it.

These tests were originally part of a battery of tests shipping with
Android's libsync that were rewritten to use the new userspace interfaces.

An older version of this set was sent as an RFC series back in March. Now
that the framework has been destaged, I'm resending them with a few
changes - some tests were removed, and some bugs were squashed. See [0]
if you wish to see the the old set.

As usual, all comments are welcome.

Cheers!
Emilio

[0] 
http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/2016-March/086932.html

Emilio López (7):
  selftest: sync: basic tests for sw_sync framework
  selftest: sync: fence tests for sw_sync framework
  selftest: sync: merge tests for sw_sync framework
  selftest: sync: wait tests for sw_sync framework
  selftest: sync: stress test for parallelism
  selftest: sync: stress consumer/producer test
  selftest: sync: stress test for merges

 tools/testing/selftests/Makefile   |   1 +
 tools/testing/selftests/sync/.gitignore|   1 +
 tools/testing/selftests/sync/Makefile  |  30 +++
 tools/testing/selftests/sync/sw_sync.h |  46 +
 tools/testing/selftests/sync/sync.c| 222 +
 tools/testing/selftests/sync/sync.h|  40 
 tools/testing/selftests/sync/sync_alloc.c  |  74 +++
 tools/testing/selftests/sync/sync_fence.c  | 132 
 tools/testing/selftests/sync/sync_merge.c  |  60 ++
 .../testing/selftests/sync/sync_stress_consumer.c  | 185 +
 tools/testing/selftests/sync/sync_stress_merge.c   | 116 +++
 .../selftests/sync/sync_stress_parallelism.c   | 111 +++
 tools/testing/selftests/sync/sync_test.c   |  79 
 tools/testing/selftests/sync/sync_wait.c   |  91 +
 tools/testing/selftests/sync/synctest.h|  66 ++
 15 files changed, 1254 insertions(+)
 create mode 100644 tools/testing/selftests/sync/.gitignore
 create mode 100644 tools/testing/selftests/sync/Makefile
 create mode 100644 tools/testing/selftests/sync/sw_sync.h
 create mode 100644 tools/testing/selftests/sync/sync.c
 create mode 100644 tools/testing/selftests/sync/sync.h
 create mode 100644 tools/testing/selftests/sync/sync_alloc.c
 create mode 100644 tools/testing/selftests/sync/sync_fence.c
 create mode 100644 tools/testing/selftests/sync/sync_merge.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_consumer.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_merge.c
 create mode 100644 tools/testing/selftests/sync/sync_stress_parallelism.c
 create mode 100644 tools/testing/selftests/sync/sync_test.c
 create mode 100644 tools/testing/selftests/sync/sync_wait.c
 create mode 100644 tools/testing/selftests/sync/synctest.h

-- 
2.9.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/7] selftest: sync: basic tests for sw_sync framework

2016-09-21 Thread Emilio López
These tests are based on the libsync test suite from Android.
This commit lays the ground for future tests, as well as includes
tests for a variety of basic allocation commands.

Signed-off-by: Emilio López 
---
 tools/testing/selftests/Makefile  |   1 +
 tools/testing/selftests/sync/.gitignore   |   1 +
 tools/testing/selftests/sync/Makefile |  24 
 tools/testing/selftests/sync/sw_sync.h|  46 +++
 tools/testing/selftests/sync/sync.c   | 222 ++
 tools/testing/selftests/sync/sync.h   |  40 ++
 tools/testing/selftests/sync/sync_alloc.c |  74 ++
 tools/testing/selftests/sync/sync_test.c  |  71 ++
 tools/testing/selftests/sync/synctest.h   |  47 +++
 9 files changed, 526 insertions(+)
 create mode 100644 tools/testing/selftests/sync/.gitignore
 create mode 100644 tools/testing/selftests/sync/Makefile
 create mode 100644 tools/testing/selftests/sync/sw_sync.h
 create mode 100644 tools/testing/selftests/sync/sync.c
 create mode 100644 tools/testing/selftests/sync/sync.h
 create mode 100644 tools/testing/selftests/sync/sync_alloc.c
 create mode 100644 tools/testing/selftests/sync/sync_test.c
 create mode 100644 tools/testing/selftests/sync/synctest.h

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index ff9e5f2..a72e3c7 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -22,6 +22,7 @@ TARGETS += seccomp
 TARGETS += sigaltstack
 TARGETS += size
 TARGETS += static_keys
+TARGETS += sync
 TARGETS += sysctl
 ifneq (1, $(quicktest))
 TARGETS += timers
diff --git a/tools/testing/selftests/sync/.gitignore 
b/tools/testing/selftests/sync/.gitignore
new file mode 100644
index 000..f5091e7
--- /dev/null
+++ b/tools/testing/selftests/sync/.gitignore
@@ -0,0 +1 @@
+sync_test
diff --git a/tools/testing/selftests/sync/Makefile 
b/tools/testing/selftests/sync/Makefile
new file mode 100644
index 000..f67827f
--- /dev/null
+++ b/tools/testing/selftests/sync/Makefile
@@ -0,0 +1,24 @@
+CC = $(CROSS_COMPILE)gcc
+CFLAGS := -O2 -g -std=gnu89 -pthread -Wall -Wextra
+CFLAGS += -I../../../../include/uapi/
+CFLAGS += -I../../../../include/
+CFLAGS += -I../../../../usr/include/
+CFLAGS += -I../../../../drivers/dma-buf/
+LDFLAGS += -pthread
+
+TEST_PROGS = sync_test
+
+all: $(TEST_PROGS)
+
+include ../lib.mk
+
+SRC = sync_test.o sync.o
+
+TESTS += sync_alloc.o
+
+sync_test: $(SRC) $(TESTS)
+
+.PHONY: clean
+
+clean:
+   $(RM) sync_test $(SRC) $(TESTS)
diff --git a/tools/testing/selftests/sync/sw_sync.h 
b/tools/testing/selftests/sync/sw_sync.h
new file mode 100644
index 000..e2cfc6ba
--- /dev/null
+++ b/tools/testing/selftests/sync/sw_sync.h
@@ -0,0 +1,46 @@
+/*
+ *  sw_sync abstraction
+ *
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2013 Google, Inc
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a
+ *  copy of this software and associated documentation files (the "Software"),
+ *  to deal in the Software without restriction, including without limitation
+ *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ *  and/or sell copies of the Software, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *  OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef SELFTESTS_SW_SYNC_H
+#define SELFTESTS_SW_SYNC_H
+
+/*
+ * sw_sync is mainly intended for testing and should not be compiled into
+ * production kernels
+ */
+
+int sw_sync_timeline_create(void);
+int sw_sync_timeline_is_valid(int fd);
+int sw_sync_timeline_inc(int fd, unsigned int count);
+void sw_sync_timeline_destroy(int fd);
+
+int sw_sync_fence_create(int fd, const char *name, unsigned int value);
+int sw_sync_fence_is_valid(int fd);
+void sw_sync_fence_destroy(int fd);
+
+#endif
diff --git a/tools/testing/selftests/sync/sync.c 
b/tools/testing/selftests/sync/sync.c
new file mode 100644
index 000..99368be
--- /dev/null
+++ b/tools/testing/selftests/sync/sync.c
@@ -0,0 +1,222 @@
+/*
+ *  sync / sw_sync abstraction
+ *  Copyright 2015-2016 Collabora Ltd.
+ *
+ *  Based on the implementation from the Android Open Source Project,
+ *
+ *  Copyright 2012 Google, Inc
+ *
+ *  Permission is hereby 

Re: [RFC PATCH v1 03/28] kvm: svm: Use the hardware provided GPA instead of page walk

2016-09-21 Thread Borislav Petkov
On Mon, Aug 22, 2016 at 07:24:07PM -0400, Brijesh Singh wrote:
> From: Tom Lendacky 
> 
> When a guest causes a NPF which requires emulation, KVM sometimes walks
> the guest page tables to translate the GVA to a GPA. This is unnecessary
> most of the time on AMD hardware since the hardware provides the GPA in
> EXITINFO2.
> 
> The only exception cases involve string operations involving rep or
> operations that use two memory locations. With rep, the GPA will only be
> the value of the initial NPF and with dual memory locations we won't know
> which memory address was translated into EXITINFO2.
> 
> Signed-off-by: Tom Lendacky 
> ---
>  arch/x86/include/asm/kvm_emulate.h |3 +++
>  arch/x86/include/asm/kvm_host.h|3 +++
>  arch/x86/kvm/svm.c |2 ++
>  arch/x86/kvm/x86.c |   17 -
>  4 files changed, 24 insertions(+), 1 deletion(-)

FWIW, LGTM. (Gotta love replying in acronyms :-))

Reviewed-by: Borislav Petkov 

-- 
Regards/Gruss,
Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
-- 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: greybus: audio_codec.c: space required before the open brace

2016-09-21 Thread Richard Groux
Minor error spotted by checkpatch.pl in greybus
space required before the open brace '{'

Signed-off-by: Richard Groux 
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_codec.c 
b/drivers/staging/greybus/audio_codec.c
index 2f70295..f347743 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -322,7 +322,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
dev_dbg(module->dev, "%s:Module update %s sequence\n", w->name,
enable ? "Enable":"Disable");
 
-   if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)){
+   if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)) {
dev_dbg(codec->dev, "No action required for %s\n", w->name);
return 0;
}
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: greybus: audio_codec.c: code indent should use tabs where possible

2016-09-21 Thread Richard Groux
Minor error spotted by checkpatch.pl in greybus
code indent should use tabs where possible

Signed-off-by: Richard Groux 
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_codec.c 
b/drivers/staging/greybus/audio_codec.c
index f347743..a46ca42 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -1008,7 +1008,7 @@ static int gbcodec_probe(struct snd_soc_codec *codec)
snd_soc_codec_set_drvdata(codec, info);
gbcodec = info;
 
-device_init_wakeup(codec->dev, 1);
+   device_init_wakeup(codec->dev, 1);
return 0;
 }
 
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: greybus: audio_codec.c: space required before the open brace

2016-09-21 Thread Greg KH
On Wed, Sep 21, 2016 at 05:11:22PM +0200, Richard Groux wrote:
> Minor error spotted by checkpatch.pl in greybus
> space required before the open brace '{'
> 
> Signed-off-by: Richard Groux 
> ---
>  drivers/staging/greybus/audio_codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Any reason you didn't cc: the people that get_maintainers.pl told you to
 cc: for patches for these files?

 thanks,

 greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: greybus: audio_codec.c: code indent should use tabs where possible

2016-09-21 Thread Richard Groux
Minor error spotted by checkpatch.pl in greybus
code indent should use tabs where possible

Signed-off-by: Richard Groux 
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_codec.c 
b/drivers/staging/greybus/audio_codec.c
index f347743..a46ca42 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -1008,7 +1008,7 @@ static int gbcodec_probe(struct snd_soc_codec *codec)
snd_soc_codec_set_drvdata(codec, info);
gbcodec = info;
 
-device_init_wakeup(codec->dev, 1);
+   device_init_wakeup(codec->dev, 1);
return 0;
 }
 
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: greybus: audio_codec.c: space required before the open brace

2016-09-21 Thread Richard Groux
Minor error spotted by checkpatch.pl in greybus
space required before the open brace '{'

Signed-off-by: Richard Groux 
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_codec.c 
b/drivers/staging/greybus/audio_codec.c
index 2f70295..f347743 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -322,7 +322,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
dev_dbg(module->dev, "%s:Module update %s sequence\n", w->name,
enable ? "Enable":"Disable");
 
-   if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)){
+   if ((w->id != snd_soc_dapm_aif_in) && (w->id != snd_soc_dapm_aif_out)) {
dev_dbg(codec->dev, "No action required for %s\n", w->name);
return 0;
}
-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/2] staging: greybus: audio_codec.c: minor error spotted by checkpatch.pl

2016-09-21 Thread Richard Groux
This patchset removes few error spotted by checkpatch.pl

Richard Groux (2):
  staging: greybus: audio_codec.c: space required before the open brace
  staging: greybus: audio_codec.c: code indent should use tabs where
possible

 drivers/staging/greybus/audio_codec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.7.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/6] staging: most: make function most_submit_mbo return void

2016-09-21 Thread Christian Gromm
Function most_submit_mbo() causes an exception only if either the pointer
mbo or mbo->context equals NULL. From the underlying architecture's point
of view both cases must _not_ come true and would happen only, if something
has tampered with the pointers. This would render runtime code unable to
recover anyway. So, instead trying to hide that things are already
critically out of control we're better off with a WARN_ON() assertion.

This patch replaces the return type of the function most_submit_mbo() with
'void' and adds a WARN_ONCE() assertion. Additionally, code calling the
function is adapted accordingly.

Signed-off-by: Christian Gromm 
---
 drivers/staging/most/aim-cdev/cdev.c |  5 +
 drivers/staging/most/aim-sound/sound.c   |  6 +-
 drivers/staging/most/mostcore/core.c | 11 ---
 drivers/staging/most/mostcore/mostcore.h |  2 +-
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/most/aim-cdev/cdev.c 
b/drivers/staging/most/aim-cdev/cdev.c
index 1c20ae6..5458fb9 100644
--- a/drivers/staging/most/aim-cdev/cdev.c
+++ b/drivers/staging/most/aim-cdev/cdev.c
@@ -214,10 +214,7 @@ static ssize_t aim_write(struct file *filp, const char 
__user *buf,
goto put_mbo;
}
 
-   ret = most_submit_mbo(mbo);
-   if (ret)
-   goto put_mbo;
-
+   most_submit_mbo(mbo);
mutex_unlock(>io_mutex);
return actual_len;
 put_mbo:
diff --git a/drivers/staging/most/aim-sound/sound.c 
b/drivers/staging/most/aim-sound/sound.c
index 9c64580..3dc625c 100644
--- a/drivers/staging/most/aim-sound/sound.c
+++ b/drivers/staging/most/aim-sound/sound.c
@@ -234,7 +234,6 @@ static int playback_thread(void *data)
while (!kthread_should_stop()) {
struct mbo *mbo = NULL;
bool period_elapsed = false;
-   int ret;
 
wait_event_interruptible(
channel->playback_waitq,
@@ -250,10 +249,7 @@ static int playback_thread(void *data)
else
memset(mbo->virt_address, 0, mbo->buffer_length);
 
-   ret = most_submit_mbo(mbo);
-   if (ret)
-   channel->is_stream_running = false;
-
+   most_submit_mbo(mbo);
if (period_elapsed)
snd_pcm_period_elapsed(channel->substream);
}
diff --git a/drivers/staging/most/mostcore/core.c 
b/drivers/staging/most/mostcore/core.c
index bd555ec..5f05a13 100644
--- a/drivers/staging/most/mostcore/core.c
+++ b/drivers/staging/most/mostcore/core.c
@@ -1323,17 +1323,14 @@ _exit:
 /**
  * most_submit_mbo - submits an MBO to fifo
  * @mbo: pointer to the MBO
- *
  */
-int most_submit_mbo(struct mbo *mbo)
+void most_submit_mbo(struct mbo *mbo)
 {
-   if (unlikely((!mbo) || (!mbo->context))) {
-   pr_err("Bad MBO or missing channel reference\n");
-   return -EINVAL;
-   }
+   if (WARN_ONCE(!mbo || !mbo->context,
+ "bad mbo or missing channel reference\n"))
+   return;
 
nq_hdm_mbo(mbo);
-   return 0;
 }
 EXPORT_SYMBOL_GPL(most_submit_mbo);
 
diff --git a/drivers/staging/most/mostcore/mostcore.h 
b/drivers/staging/most/mostcore/mostcore.h
index e768cb8..7644f44 100644
--- a/drivers/staging/most/mostcore/mostcore.h
+++ b/drivers/staging/most/mostcore/mostcore.h
@@ -287,7 +287,7 @@ struct kobject *most_register_interface(struct 
most_interface *iface);
  * @intf_instance Pointer to the interface instance description.
  */
 void most_deregister_interface(struct most_interface *iface);
-int most_submit_mbo(struct mbo *mbo);
+void most_submit_mbo(struct mbo *mbo);
 
 /**
  * most_stop_enqueue - prevents core from enqueing MBOs
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/6] staging: most: aim-cdev: make syscall write accept buffers of arbitrary size

2016-09-21 Thread Christian Gromm
From: Andrey Shvetsov 

This patch allows to call the write() function for synchronous and
isochronous channels with buffers of any size. The AIM simply waits for
data to fill up the MOST buffer object according to the network interface
controller specification for streaming channels, before it submits the
buffer to the HDM.

The new behavior is backward compatible to the old applications, since
all known applications needed to fill the buffer completely anyway.

Signed-off-by: Andrey Shvetsov 
Signed-off-by: Christian Gromm 
---
 drivers/staging/most/aim-cdev/cdev.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/most/aim-cdev/cdev.c 
b/drivers/staging/most/aim-cdev/cdev.c
index f6a7b75..0a06d7f 100644
--- a/drivers/staging/most/aim-cdev/cdev.c
+++ b/drivers/staging/most/aim-cdev/cdev.c
@@ -57,7 +57,11 @@ static inline bool ch_has_mbo(struct aim_channel *c)
 
 static inline bool ch_get_mbo(struct aim_channel *c, struct mbo **mbo)
 {
-   *mbo = most_get_mbo(c->iface, c->channel_id, _aim);
+   if (!kfifo_peek(>fifo, mbo)) {
+   *mbo = most_get_mbo(c->iface, c->channel_id, _aim);
+   if (*mbo)
+   kfifo_in(>fifo, mbo, 1);
+   }
return *mbo;
 }
 
@@ -183,8 +187,7 @@ static int aim_close(struct inode *inode, struct file *filp)
 static ssize_t aim_write(struct file *filp, const char __user *buf,
 size_t count, loff_t *offset)
 {
-   size_t actual_len;
-   size_t max_len;
+   size_t to_copy, left;
struct mbo *mbo = NULL;
struct aim_channel *c = filp->private_data;
 
@@ -204,19 +207,25 @@ static ssize_t aim_write(struct file *filp, const char 
__user *buf,
return -ENODEV;
}
 
-   max_len = c->cfg->buffer_size;
-   actual_len = min(count, max_len);
-   mbo->buffer_length = actual_len;
-
-   if (copy_from_user(mbo->virt_address, buf, mbo->buffer_length)) {
-   most_put_mbo(mbo);
+   to_copy = min(count, c->cfg->buffer_size - c->mbo_offs);
+   left = copy_from_user(mbo->virt_address + c->mbo_offs, buf, to_copy);
+   if (left == to_copy) {
mutex_unlock(>io_mutex);
return -EFAULT;
}
 
-   most_submit_mbo(mbo);
+   c->mbo_offs += to_copy - left;
+   if (c->mbo_offs >= c->cfg->buffer_size ||
+   c->cfg->data_type == MOST_CH_CONTROL ||
+   c->cfg->data_type == MOST_CH_ASYNC) {
+   kfifo_skip(>fifo);
+   mbo->buffer_length = c->mbo_offs;
+   c->mbo_offs = 0;
+   most_submit_mbo(mbo);
+   }
+
mutex_unlock(>io_mutex);
-   return actual_len;
+   return to_copy - left;
 }
 
 /**
@@ -282,7 +291,7 @@ static unsigned int aim_poll(struct file *filp, poll_table 
*wait)
if (!kfifo_is_empty(>fifo))
mask |= POLLIN | POLLRDNORM;
} else {
-   if (ch_has_mbo(c))
+   if (!kfifo_is_empty(>fifo) || ch_has_mbo(c))
mask |= POLLOUT | POLLWRNORM;
}
return mask;
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/6] staging: most: replace MOST_CH_ISOC_AVP with MOST_CH_ISOC

2016-09-21 Thread Christian Gromm
From: Andrey Shvetsov 

This patch replaces the enum value MOST_CH_ISOC_AVP with the more
appropriate MOST_CH_ISOC.

Signed-off-by: Andrey Shvetsov 
Signed-off-by: Christian Gromm 
---
 drivers/staging/most/aim-v4l2/video.c| 2 +-
 drivers/staging/most/hdm-dim2/dim2_hdm.c | 4 ++--
 drivers/staging/most/hdm-usb/hdm_usb.c   | 8 
 drivers/staging/most/mostcore/core.c | 6 +++---
 drivers/staging/most/mostcore/mostcore.h | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/most/aim-v4l2/video.c 
b/drivers/staging/most/aim-v4l2/video.c
index 9173cd1..400f727 100644
--- a/drivers/staging/most/aim-v4l2/video.c
+++ b/drivers/staging/most/aim-v4l2/video.c
@@ -505,7 +505,7 @@ static int aim_probe_channel(struct most_interface *iface, 
int channel_idx,
}
 
if (ccfg->data_type != MOST_CH_SYNC &&
-   ccfg->data_type != MOST_CH_ISOC_AVP) {
+   ccfg->data_type != MOST_CH_ISOC) {
pr_err("wrong channel type, expect sync or isoc\n");
return -EINVAL;
}
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c 
b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index 71f4ae7..78b2c3d 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -561,7 +561,7 @@ static int configure_channel(struct most_interface 
*most_iface, int ch_idx,
hal_ret = dim_init_async(_ch->ch, is_tx, ch_addr,
 is_tx ? new_size * 2 : new_size);
break;
-   case MOST_CH_ISOC_AVP:
+   case MOST_CH_ISOC:
new_size = dim_norm_isoc_buffer_size(buf_size, sub_size);
if (new_size == 0) {
pr_err("%s: invalid sub-buffer size or too small buffer 
size\n",
@@ -797,7 +797,7 @@ static int dim2_probe(struct platform_device *pdev)
cap->name_suffix = hdm_ch->name;
cap->direction = MOST_CH_RX | MOST_CH_TX;
cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
-MOST_CH_ISOC_AVP | MOST_CH_SYNC;
+MOST_CH_ISOC | MOST_CH_SYNC;
cap->num_buffers_packet = MAX_BUFFERS_PACKET;
cap->buffer_size_packet = MAX_BUF_SIZE_PACKET;
cap->num_buffers_streaming = MAX_BUFFERS_STREAMING;
diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c 
b/drivers/staging/most/hdm-usb/hdm_usb.c
index 9deb28c..8f17ba1 100644
--- a/drivers/staging/most/hdm-usb/hdm_usb.c
+++ b/drivers/staging/most/hdm-usb/hdm_usb.c
@@ -224,7 +224,7 @@ static unsigned int get_stream_frame_size(struct 
most_channel_config *cfg)
return frame_size;
}
switch (cfg->data_type) {
-   case MOST_CH_ISOC_AVP:
+   case MOST_CH_ISOC:
frame_size = AV_PACKETS_PER_XACT * sub_size;
break;
case MOST_CH_SYNC:
@@ -634,7 +634,7 @@ static int hdm_enqueue(struct most_interface *iface, int 
channel,
  length,
  hdm_write_completion,
  mbo);
-   if (conf->data_type != MOST_CH_ISOC_AVP)
+   if (conf->data_type != MOST_CH_ISOC)
urb->transfer_flags |= URB_ZERO_PACKET;
} else {
usb_fill_bulk_urb(urb, mdev->usb_device,
@@ -698,7 +698,7 @@ static int hdm_configure_channel(struct most_interface 
*iface, int channel,
}
 
if (conf->data_type != MOST_CH_SYNC &&
-   !(conf->data_type == MOST_CH_ISOC_AVP &&
+   !(conf->data_type == MOST_CH_ISOC &&
  conf->packets_per_xact != 0xFF)) {
mdev->padding_active[channel] = false;
goto exit;
@@ -1254,7 +1254,7 @@ hdm_probe(struct usb_interface *interface, const struct 
usb_device_id *id)
tmp_cap->num_buffers_packet = BUF_CHAIN_SIZE;
tmp_cap->num_buffers_streaming = BUF_CHAIN_SIZE;
tmp_cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
-MOST_CH_ISOC_AVP | MOST_CH_SYNC;
+MOST_CH_ISOC | MOST_CH_SYNC;
if (usb_endpoint_dir_in(ep_desc))
tmp_cap->direction = MOST_CH_RX;
else
diff --git a/drivers/staging/most/mostcore/core.c 
b/drivers/staging/most/mostcore/core.c
index d7c3f46..329109c 100644
--- a/drivers/staging/most/mostcore/core.c
+++ b/drivers/staging/most/mostcore/core.c
@@ -87,8 +87,8 @@ static const struct {
{ MOST_CH_CONTROL, "control\n" },
{ MOST_CH_ASYNC, "async\n" },
{ MOST_CH_SYNC, "sync\n" },
-   { MOST_CH_ISOC_AVP, "isoc\n"},
-   { MOST_CH_ISOC_AVP, "isoc_avp\n"},
+   { MOST_CH_ISOC, "isoc\n"},
+   { MOST_CH_ISOC, "isoc_avp\n"},
 };
 
 #define to_inst_obj(d) 

[PATCH 4/6] staging: most: core: remove trailing zero from text property

2016-09-21 Thread Christian Gromm
From: Andrey Shvetsov 

This patch removes trailing zeros from the strings returned by the
attributes available_datatypes and available_directions.

Signed-off-by: Andrey Shvetsov 
Signed-off-by: Christian Gromm 
---
 drivers/staging/most/mostcore/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/mostcore/core.c 
b/drivers/staging/most/mostcore/core.c
index 5f05a13..29e8a1c 100644
--- a/drivers/staging/most/mostcore/core.c
+++ b/drivers/staging/most/mostcore/core.c
@@ -265,7 +265,7 @@ static ssize_t show_available_directions(struct most_c_obj 
*c,
if (c->iface->channel_vector[i].direction & MOST_CH_TX)
strcat(buf, "dir_tx ");
strcat(buf, "\n");
-   return strlen(buf) + 1;
+   return strlen(buf);
 }
 
 static ssize_t show_available_datatypes(struct most_c_obj *c,
@@ -284,7 +284,7 @@ static ssize_t show_available_datatypes(struct most_c_obj 
*c,
if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC_AVP)
strcat(buf, "isoc_avp ");
strcat(buf, "\n");
-   return strlen(buf) + 1;
+   return strlen(buf);
 }
 
 static
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/6] staging: most: clean up configuration strings

2016-09-21 Thread Christian Gromm
This patch adds the strings 'rx', 'tx' and 'isoc' to the list of accepted
identifiers when setting up a channel configuration. To keep consistency it
removes the prefix "dir_" from strings returned by the attributes
set_direction and available_directions and it removes the suffix "_avp"
from the string "isoc_avp" returned by the attributes set_datatype and
available_datatypes.

Signed-off-by: Christian Gromm 
---
 drivers/staging/most/aim-v4l2/video.c |  2 +-
 drivers/staging/most/mostcore/core.c  | 21 ++---
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/most/aim-v4l2/video.c 
b/drivers/staging/most/aim-v4l2/video.c
index 150dc89..9173cd1 100644
--- a/drivers/staging/most/aim-v4l2/video.c
+++ b/drivers/staging/most/aim-v4l2/video.c
@@ -506,7 +506,7 @@ static int aim_probe_channel(struct most_interface *iface, 
int channel_idx,
 
if (ccfg->data_type != MOST_CH_SYNC &&
ccfg->data_type != MOST_CH_ISOC_AVP) {
-   pr_err("wrong channel type, expect sync or isoc_avp\n");
+   pr_err("wrong channel type, expect sync or isoc\n");
return -EINVAL;
}
 
diff --git a/drivers/staging/most/mostcore/core.c 
b/drivers/staging/most/mostcore/core.c
index 29e8a1c..d7c3f46 100644
--- a/drivers/staging/most/mostcore/core.c
+++ b/drivers/staging/most/mostcore/core.c
@@ -83,10 +83,13 @@ struct most_inst_obj {
 static const struct {
int most_ch_data_type;
char *name;
-} ch_data_type[] = { { MOST_CH_CONTROL, "control\n" },
+} ch_data_type[] = {
+   { MOST_CH_CONTROL, "control\n" },
{ MOST_CH_ASYNC, "async\n" },
{ MOST_CH_SYNC, "sync\n" },
-   { MOST_CH_ISOC_AVP, "isoc_avp\n"} };
+   { MOST_CH_ISOC_AVP, "isoc\n"},
+   { MOST_CH_ISOC_AVP, "isoc_avp\n"},
+};
 
 #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
 
@@ -261,9 +264,9 @@ static ssize_t show_available_directions(struct most_c_obj 
*c,
 
strcpy(buf, "");
if (c->iface->channel_vector[i].direction & MOST_CH_RX)
-   strcat(buf, "dir_rx ");
+   strcat(buf, "rx ");
if (c->iface->channel_vector[i].direction & MOST_CH_TX)
-   strcat(buf, "dir_tx ");
+   strcat(buf, "tx ");
strcat(buf, "\n");
return strlen(buf);
 }
@@ -282,7 +285,7 @@ static ssize_t show_available_datatypes(struct most_c_obj 
*c,
if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
strcat(buf, "sync ");
if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC_AVP)
-   strcat(buf, "isoc_avp ");
+   strcat(buf, "isoc ");
strcat(buf, "\n");
return strlen(buf);
 }
@@ -392,9 +395,9 @@ static ssize_t show_set_direction(struct most_c_obj *c,
  char *buf)
 {
if (c->cfg.direction & MOST_CH_TX)
-   return snprintf(buf, PAGE_SIZE, "dir_tx\n");
+   return snprintf(buf, PAGE_SIZE, "tx\n");
else if (c->cfg.direction & MOST_CH_RX)
-   return snprintf(buf, PAGE_SIZE, "dir_rx\n");
+   return snprintf(buf, PAGE_SIZE, "rx\n");
return snprintf(buf, PAGE_SIZE, "unconfigured\n");
 }
 
@@ -405,8 +408,12 @@ static ssize_t store_set_direction(struct most_c_obj *c,
 {
if (!strcmp(buf, "dir_rx\n")) {
c->cfg.direction = MOST_CH_RX;
+   } else if (!strcmp(buf, "rx\n")) {
+   c->cfg.direction = MOST_CH_RX;
} else if (!strcmp(buf, "dir_tx\n")) {
c->cfg.direction = MOST_CH_TX;
+   } else if (!strcmp(buf, "tx\n")) {
+   c->cfg.direction = MOST_CH_TX;
} else {
pr_info("WARN: invalid attribute settings\n");
return -EINVAL;
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/6] staging: most: aim-cdev: remove labels

2016-09-21 Thread Christian Gromm
From: Andrey Shvetsov 

This patch removes the labels 'put_mbo' and 'unlock' and relocates the
code accordingly making the code look simpler.

Signed-off-by: Andrey Shvetsov 
Signed-off-by: Christian Gromm 
---
 drivers/staging/most/aim-cdev/cdev.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/most/aim-cdev/cdev.c 
b/drivers/staging/most/aim-cdev/cdev.c
index 5458fb9..f6a7b75 100644
--- a/drivers/staging/most/aim-cdev/cdev.c
+++ b/drivers/staging/most/aim-cdev/cdev.c
@@ -183,7 +183,6 @@ static int aim_close(struct inode *inode, struct file *filp)
 static ssize_t aim_write(struct file *filp, const char __user *buf,
 size_t count, loff_t *offset)
 {
-   int ret;
size_t actual_len;
size_t max_len;
struct mbo *mbo = NULL;
@@ -201,8 +200,8 @@ static ssize_t aim_write(struct file *filp, const char 
__user *buf,
}
 
if (unlikely(!c->dev)) {
-   ret = -ENODEV;
-   goto unlock;
+   mutex_unlock(>io_mutex);
+   return -ENODEV;
}
 
max_len = c->cfg->buffer_size;
@@ -210,18 +209,14 @@ static ssize_t aim_write(struct file *filp, const char 
__user *buf,
mbo->buffer_length = actual_len;
 
if (copy_from_user(mbo->virt_address, buf, mbo->buffer_length)) {
-   ret = -EFAULT;
-   goto put_mbo;
+   most_put_mbo(mbo);
+   mutex_unlock(>io_mutex);
+   return -EFAULT;
}
 
most_submit_mbo(mbo);
mutex_unlock(>io_mutex);
return actual_len;
-put_mbo:
-   most_put_mbo(mbo);
-unlock:
-   mutex_unlock(>io_mutex);
-   return ret;
 }
 
 /**
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/6] staging: most: fix driver modules

2016-09-21 Thread Christian Gromm
This patch set is needed to fix up issues of the driver modules.

Andrey Shvetsov (4):
  staging: most: aim-cdev: remove labels
  staging: most: aim-cdev: make syscall write accept buffers of
arbitrary size
  staging: most: core: remove trailing zero from text property
  staging: most: replace MOST_CH_ISOC_AVP with MOST_CH_ISOC

Christian Gromm (2):
  staging: most: make function most_submit_mbo return void
  staging: most: clean up configuration strings

 drivers/staging/most/aim-cdev/cdev.c | 47 
 drivers/staging/most/aim-sound/sound.c   |  6 +---
 drivers/staging/most/aim-v4l2/video.c|  4 +--
 drivers/staging/most/hdm-dim2/dim2_hdm.c |  4 +--
 drivers/staging/most/hdm-usb/hdm_usb.c   |  8 +++---
 drivers/staging/most/mostcore/core.c | 38 ++
 drivers/staging/most/mostcore/mostcore.h |  4 +--
 7 files changed, 56 insertions(+), 55 deletions(-)

-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC PATCH v1 02/28] kvm: svm: Add kvm_fast_pio_in support

2016-09-21 Thread Borislav Petkov
On Mon, Aug 22, 2016 at 07:23:54PM -0400, Brijesh Singh wrote:
> From: Tom Lendacky 
> 
> Update the I/O interception support to add the kvm_fast_pio_in function
> to speed up the in instruction similar to the out instruction.
> 
> Signed-off-by: Tom Lendacky 
> ---
>  arch/x86/include/asm/kvm_host.h |1 +
>  arch/x86/kvm/svm.c  |5 +++--
>  arch/x86/kvm/x86.c  |   43 
> +++
>  3 files changed, 47 insertions(+), 2 deletions(-)

FWIW: Reviewed-by: Borislav Petkov 

-- 
Regards/Gruss,
Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
-- 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel