Re: [PATCH 3/3] ipoctal: get carrier driver to avoid rmmod

2014-09-03 Thread Samuel Iglesias Gonsálvez

On Tue, 2014-09-02 at 17:31 +0200, Federico Vaga wrote:
> Signed-off-by: Federico Vaga 
> ---
>  drivers/ipack/devices/ipoctal.c |   30 +++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
> index e531379..035d544 100644
> --- a/drivers/ipack/devices/ipoctal.c
> +++ b/drivers/ipack/devices/ipoctal.c
> @@ -55,6 +55,12 @@ struct ipoctal {
>   u8 __iomem  *int_space;
>  };
>  
> +static inline struct ipoctal *chan_to_ipoctal(struct ipoctal_channel *chan,
> +   unsigned int index)
> +{
> + return container_of(chan, struct ipoctal, channel[index]);
> +}
> +
>  static void ipoctal_reset_channel(struct ipoctal_channel *channel)
>  {
>   iowrite8(CR_DISABLE_RX | CR_DISABLE_TX, >regs->w.cr);
> @@ -82,12 +88,20 @@ static int ipoctal_port_activate(struct tty_port *port, 
> struct tty_struct *tty)
>  
>  static int ipoctal_open(struct tty_struct *tty, struct file *file)
>  {
> - struct ipoctal_channel *channel;
> + struct ipoctal_channel *channel = dev_get_drvdata(tty->dev);
> + struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index);
> + int err;
>  
> - channel = dev_get_drvdata(tty->dev);
>   tty->driver_data = channel;
>  
> - return tty_port_open(>tty_port, tty, file);
> + if (!ipack_get_carrier(ipoctal->dev))
> + return -EBUSY;
> +
> + err = tty_port_open(>tty_port, tty, file);
> + if (err)
> + ipack_put_carrier(ipoctal->dev);
> +
> + return err;
>  }
>  
>  static void ipoctal_reset_stats(struct ipoctal_stats *stats)
> @@ -631,6 +645,15 @@ static void ipoctal_shutdown(struct tty_struct *tty)
>   clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
>  }
>  
> +static void ipoctal_cleanup(struct tty_struct *tty)
> +{
> + struct ipoctal_channel *channel = tty->driver_data;
> + struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index);
> +
> + /* release the carrier driver */
> + ipack_put_carrier(ipoctal->dev);
> +}
> +
>  static const struct tty_operations ipoctal_fops = {
>   .ioctl =NULL,
>   .open = ipoctal_open,
> @@ -642,6 +665,7 @@ static const struct tty_operations ipoctal_fops = {
>   .get_icount =   ipoctal_get_icount,
>   .hangup =   ipoctal_hangup,
>   .shutdown = ipoctal_shutdown,
> + .cleanup =  ipoctal_cleanup,
>  };
>  
>  static int ipoctal_probe(struct ipack_device *dev)

Acked-by: Samuel Iglesias Gonsalvez 

Greg, Can you this series through your char-misc tree?

Sam




signature.asc
Description: This is a digitally signed message part


Re: [PATCH 3/3] ipoctal: get carrier driver to avoid rmmod

2014-09-03 Thread Samuel Iglesias Gonsálvez

On Tue, 2014-09-02 at 17:31 +0200, Federico Vaga wrote:
 Signed-off-by: Federico Vaga federico.v...@cern.ch
 ---
  drivers/ipack/devices/ipoctal.c |   30 +++---
  1 file changed, 27 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
 index e531379..035d544 100644
 --- a/drivers/ipack/devices/ipoctal.c
 +++ b/drivers/ipack/devices/ipoctal.c
 @@ -55,6 +55,12 @@ struct ipoctal {
   u8 __iomem  *int_space;
  };
  
 +static inline struct ipoctal *chan_to_ipoctal(struct ipoctal_channel *chan,
 +   unsigned int index)
 +{
 + return container_of(chan, struct ipoctal, channel[index]);
 +}
 +
  static void ipoctal_reset_channel(struct ipoctal_channel *channel)
  {
   iowrite8(CR_DISABLE_RX | CR_DISABLE_TX, channel-regs-w.cr);
 @@ -82,12 +88,20 @@ static int ipoctal_port_activate(struct tty_port *port, 
 struct tty_struct *tty)
  
  static int ipoctal_open(struct tty_struct *tty, struct file *file)
  {
 - struct ipoctal_channel *channel;
 + struct ipoctal_channel *channel = dev_get_drvdata(tty-dev);
 + struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty-index);
 + int err;
  
 - channel = dev_get_drvdata(tty-dev);
   tty-driver_data = channel;
  
 - return tty_port_open(channel-tty_port, tty, file);
 + if (!ipack_get_carrier(ipoctal-dev))
 + return -EBUSY;
 +
 + err = tty_port_open(channel-tty_port, tty, file);
 + if (err)
 + ipack_put_carrier(ipoctal-dev);
 +
 + return err;
  }
  
  static void ipoctal_reset_stats(struct ipoctal_stats *stats)
 @@ -631,6 +645,15 @@ static void ipoctal_shutdown(struct tty_struct *tty)
   clear_bit(ASYNCB_INITIALIZED, channel-tty_port.flags);
  }
  
 +static void ipoctal_cleanup(struct tty_struct *tty)
 +{
 + struct ipoctal_channel *channel = tty-driver_data;
 + struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty-index);
 +
 + /* release the carrier driver */
 + ipack_put_carrier(ipoctal-dev);
 +}
 +
  static const struct tty_operations ipoctal_fops = {
   .ioctl =NULL,
   .open = ipoctal_open,
 @@ -642,6 +665,7 @@ static const struct tty_operations ipoctal_fops = {
   .get_icount =   ipoctal_get_icount,
   .hangup =   ipoctal_hangup,
   .shutdown = ipoctal_shutdown,
 + .cleanup =  ipoctal_cleanup,
  };
  
  static int ipoctal_probe(struct ipack_device *dev)

Acked-by: Samuel Iglesias Gonsalvez sigles...@igalia.com

Greg, Can you this series through your char-misc tree?

Sam




signature.asc
Description: This is a digitally signed message part


[PATCH 3/3] ipoctal: get carrier driver to avoid rmmod

2014-09-02 Thread Federico Vaga
Signed-off-by: Federico Vaga 
---
 drivers/ipack/devices/ipoctal.c |   30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index e531379..035d544 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -55,6 +55,12 @@ struct ipoctal {
u8 __iomem  *int_space;
 };
 
+static inline struct ipoctal *chan_to_ipoctal(struct ipoctal_channel *chan,
+ unsigned int index)
+{
+   return container_of(chan, struct ipoctal, channel[index]);
+}
+
 static void ipoctal_reset_channel(struct ipoctal_channel *channel)
 {
iowrite8(CR_DISABLE_RX | CR_DISABLE_TX, >regs->w.cr);
@@ -82,12 +88,20 @@ static int ipoctal_port_activate(struct tty_port *port, 
struct tty_struct *tty)
 
 static int ipoctal_open(struct tty_struct *tty, struct file *file)
 {
-   struct ipoctal_channel *channel;
+   struct ipoctal_channel *channel = dev_get_drvdata(tty->dev);
+   struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index);
+   int err;
 
-   channel = dev_get_drvdata(tty->dev);
tty->driver_data = channel;
 
-   return tty_port_open(>tty_port, tty, file);
+   if (!ipack_get_carrier(ipoctal->dev))
+   return -EBUSY;
+
+   err = tty_port_open(>tty_port, tty, file);
+   if (err)
+   ipack_put_carrier(ipoctal->dev);
+
+   return err;
 }
 
 static void ipoctal_reset_stats(struct ipoctal_stats *stats)
@@ -631,6 +645,15 @@ static void ipoctal_shutdown(struct tty_struct *tty)
clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
 }
 
+static void ipoctal_cleanup(struct tty_struct *tty)
+{
+   struct ipoctal_channel *channel = tty->driver_data;
+   struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty->index);
+
+   /* release the carrier driver */
+   ipack_put_carrier(ipoctal->dev);
+}
+
 static const struct tty_operations ipoctal_fops = {
.ioctl =NULL,
.open = ipoctal_open,
@@ -642,6 +665,7 @@ static const struct tty_operations ipoctal_fops = {
.get_icount =   ipoctal_get_icount,
.hangup =   ipoctal_hangup,
.shutdown = ipoctal_shutdown,
+   .cleanup =  ipoctal_cleanup,
 };
 
 static int ipoctal_probe(struct ipack_device *dev)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] ipoctal: get carrier driver to avoid rmmod

2014-09-02 Thread Federico Vaga
Signed-off-by: Federico Vaga federico.v...@cern.ch
---
 drivers/ipack/devices/ipoctal.c |   30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index e531379..035d544 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -55,6 +55,12 @@ struct ipoctal {
u8 __iomem  *int_space;
 };
 
+static inline struct ipoctal *chan_to_ipoctal(struct ipoctal_channel *chan,
+ unsigned int index)
+{
+   return container_of(chan, struct ipoctal, channel[index]);
+}
+
 static void ipoctal_reset_channel(struct ipoctal_channel *channel)
 {
iowrite8(CR_DISABLE_RX | CR_DISABLE_TX, channel-regs-w.cr);
@@ -82,12 +88,20 @@ static int ipoctal_port_activate(struct tty_port *port, 
struct tty_struct *tty)
 
 static int ipoctal_open(struct tty_struct *tty, struct file *file)
 {
-   struct ipoctal_channel *channel;
+   struct ipoctal_channel *channel = dev_get_drvdata(tty-dev);
+   struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty-index);
+   int err;
 
-   channel = dev_get_drvdata(tty-dev);
tty-driver_data = channel;
 
-   return tty_port_open(channel-tty_port, tty, file);
+   if (!ipack_get_carrier(ipoctal-dev))
+   return -EBUSY;
+
+   err = tty_port_open(channel-tty_port, tty, file);
+   if (err)
+   ipack_put_carrier(ipoctal-dev);
+
+   return err;
 }
 
 static void ipoctal_reset_stats(struct ipoctal_stats *stats)
@@ -631,6 +645,15 @@ static void ipoctal_shutdown(struct tty_struct *tty)
clear_bit(ASYNCB_INITIALIZED, channel-tty_port.flags);
 }
 
+static void ipoctal_cleanup(struct tty_struct *tty)
+{
+   struct ipoctal_channel *channel = tty-driver_data;
+   struct ipoctal *ipoctal = chan_to_ipoctal(channel, tty-index);
+
+   /* release the carrier driver */
+   ipack_put_carrier(ipoctal-dev);
+}
+
 static const struct tty_operations ipoctal_fops = {
.ioctl =NULL,
.open = ipoctal_open,
@@ -642,6 +665,7 @@ static const struct tty_operations ipoctal_fops = {
.get_icount =   ipoctal_get_icount,
.hangup =   ipoctal_hangup,
.shutdown = ipoctal_shutdown,
+   .cleanup =  ipoctal_cleanup,
 };
 
 static int ipoctal_probe(struct ipack_device *dev)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/