aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/hvc
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-04-02 07:54:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-09 14:28:19 -0400
commit2cd9fa254508f71bd3025992ef5cecbf2120b0e4 (patch)
treed7cd1d06033c0187b4bbfc25d2f3f9b57e1f5e50 /drivers/tty/hvc
parent1997cf044853a2d83cd0ebc307e292fa9fa819de (diff)
TTY: hvcs, use kref from tty_port
A simple switch. Except we convert destroy_hvcs_struct to be tty_port_operations->destruct... Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/hvc')
-rw-r--r--drivers/tty/hvc/hvcs.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index a049ced97430..817f94bf95a1 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -290,12 +290,11 @@ struct hvcs_struct {
290 int chars_in_buffer; 290 int chars_in_buffer;
291 291
292 /* 292 /*
293 * Any variable below the kref is valid before a tty is connected and 293 * Any variable below is valid before a tty is connected and
294 * stays valid after the tty is disconnected. These shouldn't be 294 * stays valid after the tty is disconnected. These shouldn't be
295 * whacked until the kobject refcount reaches zero though some entries 295 * whacked until the kobject refcount reaches zero though some entries
296 * may be changed via sysfs initiatives. 296 * may be changed via sysfs initiatives.
297 */ 297 */
298 struct kref kref; /* ref count & hvcs_struct lifetime */
299 int connected; /* is the vty-server currently connected to a vty? */ 298 int connected; /* is the vty-server currently connected to a vty? */
300 uint32_t p_unit_address; /* partner unit address */ 299 uint32_t p_unit_address; /* partner unit address */
301 uint32_t p_partition_ID; /* partner partition ID */ 300 uint32_t p_partition_ID; /* partner partition ID */
@@ -304,9 +303,6 @@ struct hvcs_struct {
304 struct vio_dev *vdev; 303 struct vio_dev *vdev;
305}; 304};
306 305
307/* Required to back map a kref to its containing object */
308#define from_kref(k) container_of(k, struct hvcs_struct, kref)
309
310static LIST_HEAD(hvcs_structs); 306static LIST_HEAD(hvcs_structs);
311static DEFINE_SPINLOCK(hvcs_structs_lock); 307static DEFINE_SPINLOCK(hvcs_structs_lock);
312static DEFINE_MUTEX(hvcs_init_mutex); 308static DEFINE_MUTEX(hvcs_init_mutex);
@@ -701,10 +697,9 @@ static void hvcs_return_index(int index)
701 hvcs_index_list[index] = -1; 697 hvcs_index_list[index] = -1;
702} 698}
703 699
704/* callback when the kref ref count reaches zero */ 700static void hvcs_destruct_port(struct tty_port *p)
705static void destroy_hvcs_struct(struct kref *kref)
706{ 701{
707 struct hvcs_struct *hvcsd = from_kref(kref); 702 struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port);
708 struct vio_dev *vdev; 703 struct vio_dev *vdev;
709 unsigned long flags; 704 unsigned long flags;
710 705
@@ -741,6 +736,10 @@ static void destroy_hvcs_struct(struct kref *kref)
741 kfree(hvcsd); 736 kfree(hvcsd);
742} 737}
743 738
739static const struct tty_port_operations hvcs_port_ops = {
740 .destruct = hvcs_destruct_port,
741};
742
744static int hvcs_get_index(void) 743static int hvcs_get_index(void)
745{ 744{
746 int i; 745 int i;
@@ -790,9 +789,8 @@ static int __devinit hvcs_probe(
790 return -ENODEV; 789 return -ENODEV;
791 790
792 tty_port_init(&hvcsd->port); 791 tty_port_init(&hvcsd->port);
792 hvcsd->port.ops = &hvcs_port_ops;
793 spin_lock_init(&hvcsd->lock); 793 spin_lock_init(&hvcsd->lock);
794 /* Automatically incs the refcount the first time */
795 kref_init(&hvcsd->kref);
796 794
797 hvcsd->vdev = dev; 795 hvcsd->vdev = dev;
798 dev_set_drvdata(&dev->dev, hvcsd); 796 dev_set_drvdata(&dev->dev, hvcsd);
@@ -860,7 +858,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
860 * Let the last holder of this object cause it to be removed, which 858 * Let the last holder of this object cause it to be removed, which
861 * would probably be tty_hangup below. 859 * would probably be tty_hangup below.
862 */ 860 */
863 kref_put(&hvcsd->kref, destroy_hvcs_struct); 861 tty_port_put(&hvcsd->port);
864 862
865 /* 863 /*
866 * The hangup is a scheduled function which will auto chain call 864 * The hangup is a scheduled function which will auto chain call
@@ -1094,7 +1092,7 @@ static struct hvcs_struct *hvcs_get_by_index(int index)
1094 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1092 list_for_each_entry(hvcsd, &hvcs_structs, next) {
1095 spin_lock_irqsave(&hvcsd->lock, flags); 1093 spin_lock_irqsave(&hvcsd->lock, flags);
1096 if (hvcsd->index == index) { 1094 if (hvcsd->index == index) {
1097 kref_get(&hvcsd->kref); 1095 tty_port_get(&hvcsd->port);
1098 spin_unlock_irqrestore(&hvcsd->lock, flags); 1096 spin_unlock_irqrestore(&hvcsd->lock, flags);
1099 spin_unlock(&hvcs_structs_lock); 1097 spin_unlock(&hvcs_structs_lock);
1100 return hvcsd; 1098 return hvcsd;
@@ -1160,7 +1158,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
1160 * and will grab the spinlock and free the connection if it fails. 1158 * and will grab the spinlock and free the connection if it fails.
1161 */ 1159 */
1162 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { 1160 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {
1163 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1161 tty_port_put(&hvcsd->port);
1164 printk(KERN_WARNING "HVCS: enable device failed.\n"); 1162 printk(KERN_WARNING "HVCS: enable device failed.\n");
1165 return rc; 1163 return rc;
1166 } 1164 }
@@ -1171,7 +1169,7 @@ fast_open:
1171 hvcsd = tty->driver_data; 1169 hvcsd = tty->driver_data;
1172 1170
1173 spin_lock_irqsave(&hvcsd->lock, flags); 1171 spin_lock_irqsave(&hvcsd->lock, flags);
1174 kref_get(&hvcsd->kref); 1172 tty_port_get(&hvcsd->port);
1175 hvcsd->port.count++; 1173 hvcsd->port.count++;
1176 hvcsd->todo_mask |= HVCS_SCHED_READ; 1174 hvcsd->todo_mask |= HVCS_SCHED_READ;
1177 spin_unlock_irqrestore(&hvcsd->lock, flags); 1175 spin_unlock_irqrestore(&hvcsd->lock, flags);
@@ -1186,7 +1184,7 @@ open_success:
1186 1184
1187error_release: 1185error_release:
1188 spin_unlock_irqrestore(&hvcsd->lock, flags); 1186 spin_unlock_irqrestore(&hvcsd->lock, flags);
1189 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1187 tty_port_put(&hvcsd->port);
1190 1188
1191 printk(KERN_WARNING "HVCS: partner connect failed.\n"); 1189 printk(KERN_WARNING "HVCS: partner connect failed.\n");
1192 return retval; 1190 return retval;
@@ -1240,7 +1238,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1240 tty->driver_data = NULL; 1238 tty->driver_data = NULL;
1241 1239
1242 free_irq(irq, hvcsd); 1240 free_irq(irq, hvcsd);
1243 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1241 tty_port_put(&hvcsd->port);
1244 return; 1242 return;
1245 } else if (hvcsd->port.count < 0) { 1243 } else if (hvcsd->port.count < 0) {
1246 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" 1244 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
@@ -1249,7 +1247,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1249 } 1247 }
1250 1248
1251 spin_unlock_irqrestore(&hvcsd->lock, flags); 1249 spin_unlock_irqrestore(&hvcsd->lock, flags);
1252 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1250 tty_port_put(&hvcsd->port);
1253} 1251}
1254 1252
1255static void hvcs_hangup(struct tty_struct * tty) 1253static void hvcs_hangup(struct tty_struct * tty)
@@ -1301,7 +1299,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1301 * NOTE: If this hangup was signaled from user space then the 1299 * NOTE: If this hangup was signaled from user space then the
1302 * final put will never happen. 1300 * final put will never happen.
1303 */ 1301 */
1304 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1302 tty_port_put(&hvcsd->port);
1305 } 1303 }
1306} 1304}
1307 1305