[PATCH 3/3] remove mutex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: michael musset <mickamusset@xxxxxxxxx>
---
 drivers/tty/serial/max310x.c | 46 ++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 562e5e3..328bbe0 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -290,7 +290,6 @@ static struct uart_driver max310x_uart_driver = {
 };
 
 static struct max310x_port *max310xs[MAX_MAX310X]; /* the chips */
-static DEFINE_MUTEX(max310xs_lock);                /* race on probe */
 static int uart_driver_registered;		   /* flag to indicate if the driver is registered*/
 static int number_of_uarts;			   /* numbe of uarts*/
 
@@ -1104,8 +1103,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 
 	if (IS_ERR(regmap))
 		return PTR_ERR(regmap);
-	// protection :
-	mutex_lock(&max310xs_lock);
 	// did we registered the driver ?
 	if (!uart_driver_registered) {
 		 // no, let's do it :
@@ -1115,7 +1112,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
                  retval = uart_register_driver(&max310x_uart_driver);
                  if (retval) {
 			// something goes wrong :
-                         mutex_unlock(&max310xs_lock);
                          return retval;
                  }
 		 number_of_uarts=0;
@@ -1128,7 +1124,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
         if (k == MAX_MAX310X) {
 		// no more space available
                 dev_warn(dev, "too many MAX310X chips\n");
-                 mutex_unlock(&max310xs_lock);
                  return -ENOMEM;
         }
 
@@ -1137,7 +1132,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 	max310xs[k] =s = devm_kzalloc(dev, sizeof(*s) +
 			 sizeof(struct max310x_one) * devtype->nr, GFP_KERNEL);
 	
-	mutex_unlock(&max310xs_lock);
 
 	if (!s) {
 		dev_err(dev, "Error allocating port structure\n");
@@ -1145,7 +1139,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 	}
 	// save the index of the array
 	s->index=k;
-	// test if we can get the frequency of the clock from the dts file :
+	// test if we can get the frequency of the clock from the property :
 	if (of_find_property(dev->of_node, "clock-frequency", NULL)){
 		// cool, let's get it :
 		of_property_read_u32(dev->of_node, "clock-frequency", &freq);
@@ -1157,6 +1151,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
                fmax = 4000000;
                xtal = 0;
         }else{
+		// we need an internal clock
 		clk_osc = devm_clk_get(dev, "osc");
 		clk_xtal = devm_clk_get(dev, "xtal");
 		if (!IS_ERR(clk_osc)) {
@@ -1222,31 +1217,32 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 	uartclk = max310x_set_ref_clk(s, freq, xtal);
 	s->nr 	= devtype->nr;
 
-// maybe we shouldn't offer the possibility to config the gpio if the user want to use the full rts pins :
-// todo: add a if with a test flag of the dts file :
+	// check if we should add gpio support to this max310x:
 #ifdef CONFIG_GPIOLIB
-	/* Setup GPIO cotroller */
-	s->gpio.owner		= THIS_MODULE;
-	s->gpio.dev		= dev;
-	s->gpio.label		= dev_name(dev);
-	s->gpio.direction_input	= max310x_gpio_direction_input;
-	s->gpio.get		= max310x_gpio_get;
-	s->gpio.direction_output= max310x_gpio_direction_output;
-	s->gpio.set		= max310x_gpio_set;
-	s->gpio.base		= -1;
-	s->gpio.ngpio		= devtype->nr * 4;
-	s->gpio.can_sleep	= 1;
-	ret = gpiochip_add(&s->gpio);
-	if (ret){
-		goto out_uart;
+	if (!of_find_property(dev->of_node, "no-gpio", NULL)){
+		/* Setup GPIO cotroller */
+		s->gpio.owner		= THIS_MODULE;
+		s->gpio.dev		= dev;
+		s->gpio.label		= dev_name(dev);
+		s->gpio.direction_input	= max310x_gpio_direction_input;
+		s->gpio.get		= max310x_gpio_get;
+		s->gpio.direction_output= max310x_gpio_direction_output;
+		s->gpio.set		= max310x_gpio_set;
+		s->gpio.base		= -1;
+		s->gpio.ngpio		= devtype->nr * 4;
+		s->gpio.can_sleep	= 1;
+		ret = gpiochip_add(&s->gpio);
+		if (ret){
+			goto out_uart;
+		}
 	}
 #endif
-
+	// init the mutex:
 	mutex_init(&s->mutex);
 	for (i = 0; i < devtype->nr; i++) {
 		/* Initialize port data */
 		//
-		s->p[i].port.line	= number_of_uarts++; // get a unique ID // maybe we need mutex here ?
+		s->p[i].port.line	= number_of_uarts++; // get a unique ID
 		s->p[i].port.dev	= dev;
 		s->p[i].port.irq	= irq;
 		s->p[i].port.type	= PORT_MAX310X;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux