tty_io.c (bbb63c514a3464342967237a51a21ea8f61ab951) | tty_io.c (6915c0e487c822e2436683e14302c0b8a6155cc7) |
---|---|
1/* 2 * Copyright (C) 1991, 1992 Linus Torvalds 3 */ 4 5/* 6 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles 7 * or rs-channels. It also implements echoing, cooked mode etc. 8 * --- 3027 unchanged lines hidden (view full) --- 3036 * driver. 3037 * 3038 * Locking: ?? 3039 */ 3040 3041struct device *tty_register_device(struct tty_driver *driver, unsigned index, 3042 struct device *device) 3043{ | 1/* 2 * Copyright (C) 1991, 1992 Linus Torvalds 3 */ 4 5/* 6 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles 7 * or rs-channels. It also implements echoing, cooked mode etc. 8 * --- 3027 unchanged lines hidden (view full) --- 3036 * driver. 3037 * 3038 * Locking: ?? 3039 */ 3040 3041struct device *tty_register_device(struct tty_driver *driver, unsigned index, 3042 struct device *device) 3043{ |
3044 struct device *ret; | 3044 return tty_register_device_attr(driver, index, device, NULL, NULL); 3045} 3046EXPORT_SYMBOL(tty_register_device); 3047 3048/** 3049 * tty_register_device_attr - register a tty device 3050 * @driver: the tty driver that describes the tty device 3051 * @index: the index in the tty driver for this tty device 3052 * @device: a struct device that is associated with this tty device. 3053 * This field is optional, if there is no known struct device 3054 * for this tty device it can be set to NULL safely. 3055 * @drvdata: Driver data to be set to device. 3056 * @attr_grp: Attribute group to be set on device. 3057 * 3058 * Returns a pointer to the struct device for this tty device 3059 * (or ERR_PTR(-EFOO) on error). 3060 * 3061 * This call is required to be made to register an individual tty device 3062 * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If 3063 * that bit is not set, this function should not be called by a tty 3064 * driver. 3065 * 3066 * Locking: ?? 3067 */ 3068struct device *tty_register_device_attr(struct tty_driver *driver, 3069 unsigned index, struct device *device, 3070 void *drvdata, 3071 const struct attribute_group **attr_grp) 3072{ |
3045 char name[64]; | 3073 char name[64]; |
3046 dev_t dev = MKDEV(driver->major, driver->minor_start) + index; | 3074 dev_t devt = MKDEV(driver->major, driver->minor_start) + index; 3075 struct device *dev = NULL; 3076 int retval = -ENODEV; |
3047 bool cdev = false; 3048 3049 if (index >= driver->num) { 3050 printk(KERN_ERR "Attempt to register invalid tty line number " 3051 " (%d).\n", index); 3052 return ERR_PTR(-EINVAL); 3053 } 3054 3055 if (driver->type == TTY_DRIVER_TYPE_PTY) 3056 pty_line_name(driver, index, name); 3057 else 3058 tty_line_name(driver, index, name); 3059 3060 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) { | 3077 bool cdev = false; 3078 3079 if (index >= driver->num) { 3080 printk(KERN_ERR "Attempt to register invalid tty line number " 3081 " (%d).\n", index); 3082 return ERR_PTR(-EINVAL); 3083 } 3084 3085 if (driver->type == TTY_DRIVER_TYPE_PTY) 3086 pty_line_name(driver, index, name); 3087 else 3088 tty_line_name(driver, index, name); 3089 3090 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) { |
3061 int error = tty_cdev_add(driver, dev, index, 1); 3062 if (error) 3063 return ERR_PTR(error); | 3091 retval = tty_cdev_add(driver, devt, index, 1); 3092 if (retval) 3093 goto error; |
3064 cdev = true; 3065 } 3066 | 3094 cdev = true; 3095 } 3096 |
3067 ret = device_create(tty_class, device, dev, NULL, name); 3068 if (IS_ERR(ret) && cdev) 3069 cdev_del(&driver->cdevs[index]); | 3097 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 3098 if (!dev) { 3099 retval = -ENOMEM; 3100 goto error; 3101 } |
3070 | 3102 |
3071 return ret; | 3103 dev->devt = devt; 3104 dev->class = tty_class; 3105 dev->parent = device; 3106 dev_set_name(dev, "%s", name); 3107 dev->groups = attr_grp; 3108 dev_set_drvdata(dev, drvdata); 3109 3110 retval = device_register(dev); 3111 if (retval) 3112 goto error; 3113 3114 return dev; 3115 3116error: 3117 put_device(dev); 3118 if (cdev) 3119 cdev_del(&driver->cdevs[index]); 3120 return ERR_PTR(retval); |
3072} | 3121} |
3073EXPORT_SYMBOL(tty_register_device); | 3122EXPORT_SYMBOL_GPL(tty_register_device_attr); |
3074 3075/** 3076 * tty_unregister_device - unregister a tty device 3077 * @driver: the tty driver that describes the tty device 3078 * @index: the index in the tty driver for this tty device 3079 * 3080 * If a tty device is registered with a call to tty_register_device() then 3081 * this function must be called when the tty device is gone. --- 390 unchanged lines hidden --- | 3123 3124/** 3125 * tty_unregister_device - unregister a tty device 3126 * @driver: the tty driver that describes the tty device 3127 * @index: the index in the tty driver for this tty device 3128 * 3129 * If a tty device is registered with a call to tty_register_device() then 3130 * this function must be called when the tty device is gone. --- 390 unchanged lines hidden --- |