static int ipoctal_probe(struct ipack_device *dev) { int res; struct ipoctal *ipoctal; ipoctal = kzalloc(sizeof(struct ipoctal), GFP_KERNEL); if (ipoctal == NULL) return -ENOMEM; ipoctal->dev = dev; res = ipoctal_inst_slot(ipoctal, dev->bus->bus_nr, dev->slot); if (res) goto out_uninst; dev_set_drvdata(&dev->dev, ipoctal); return 0; out_uninst: kfree(ipoctal); return res; }
static int ipoctal_install_all(void) { int i, j, t; int res = 0; struct tty_driver *tty; char name[20] = ""; ipoctal_installed = (struct ipoctal*) kzalloc(num_lun * sizeof(struct ipoctal), GFP_KERNEL); if (ipoctal_installed == NULL) { printk(KERN_ERR PFX "Unable to allocate memory for ipoctal's !\n"); res = -ENOMEM; goto out_err; } for (i=0; i<num_lun;i++) { tty = alloc_tty_driver(NR_CHANNELS); if(!tty) return -ENOMEM; tty->owner = THIS_MODULE; tty->driver_name = "ipoctal"; sprintf(name, "ipoctal.%d.", lun[i]); tty->name = name; tty->major = 0; tty->minor_start = 0; tty->type = TTY_DRIVER_TYPE_SERIAL; tty->subtype = SERIAL_TYPE_NORMAL; tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; tty->init_termios = tty_std_termios; tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty->init_termios.c_ispeed = 9600; tty->init_termios.c_ospeed = 9600; tty->init_termios.c_iflag = tty_std_termios.c_iflag | IGNBRK; tty_set_operations(tty, &ipoctalFops); res = tty_register_driver(tty); if(res) { printk(KERN_ERR PFX "Can't register tty driver.\n"); put_tty_driver(tty); goto out_uninst; } for(j = 0; j < NR_CHANNELS;j++) { tty_register_device(tty, j, NULL); ipoctal_installed[i].tty[j] = NULL; spin_lock_init(&ipoctal_installed[i].lock[j]); mutex_init(&ipoctal_installed[i].lock_write[j]); ipoctal_installed[i].pointer_read[j] = 0; ipoctal_installed[i].pointer_write[j] = 0; ipoctal_installed[i].nb_bytes[j] = 0; } ipoctal_installed[i].tty_drv = tty; ipoctal_installed[i].index = i; res = ipoctal_inst_slot(&ipoctal_installed[i], carrier_number[i], slot[i], irq[i], carrier[i]); if (res) { printk(KERN_ERR PFX "Error during IP octal install !\n"); goto out_uninst; } } return 0; out_uninst : for (j=0; j < i;j++){ for (t = 0; t < NR_CHANNELS; t++) tty_unregister_device(ipoctal_installed[j].tty_drv, t); tty_unregister_driver(ipoctal_installed[j].tty_drv); ipoctal_uninst_slot(&ipoctal_installed[j]); } kfree(ipoctal_installed); ipoctal_installed = NULL; printk(KERN_ERR PFX "Unregistered all IP octal devices\n"); out_err : return res; }