Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: goldfish: support platform_device with id -1

When the platform bus sets the platform_device id to -1 (PLATFORM_DEVID_NONE),
use an incrementing counter for the TTY index instead

Signed-off-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: Jin Qian <jinqian@android.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Greg Hackmann and committed by
Greg Kroah-Hartman
465893e1 9b883eea

+18 -12
+18 -12
drivers/tty/goldfish.c
··· 68 68 69 69 static irqreturn_t goldfish_tty_interrupt(int irq, void *dev_id) 70 70 { 71 - struct platform_device *pdev = dev_id; 72 - struct goldfish_tty *qtty = &goldfish_ttys[pdev->id]; 71 + struct goldfish_tty *qtty = dev_id; 73 72 void __iomem *base = qtty->base; 74 73 unsigned long irq_flags; 75 74 unsigned char *buf; ··· 232 233 struct device *ttydev; 233 234 void __iomem *base; 234 235 u32 irq; 236 + unsigned int line; 235 237 236 238 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 239 if (r == NULL) ··· 248 248 249 249 irq = r->start; 250 250 251 - if (pdev->id >= goldfish_tty_line_count) 252 - goto err_unmap; 253 - 254 251 mutex_lock(&goldfish_tty_lock); 252 + 253 + if (pdev->id == PLATFORM_DEVID_NONE) 254 + line = goldfish_tty_current_line_count; 255 + else 256 + line = pdev->id; 257 + 258 + if (line >= goldfish_tty_line_count) 259 + goto err_create_driver_failed; 260 + 255 261 if (goldfish_tty_current_line_count == 0) { 256 262 ret = goldfish_tty_create_driver(); 257 263 if (ret) ··· 265 259 } 266 260 goldfish_tty_current_line_count++; 267 261 268 - qtty = &goldfish_ttys[pdev->id]; 262 + qtty = &goldfish_ttys[line]; 269 263 spin_lock_init(&qtty->lock); 270 264 tty_port_init(&qtty->port); 271 265 qtty->port.ops = &goldfish_port_ops; ··· 275 269 writel(GOLDFISH_TTY_CMD_INT_DISABLE, base + GOLDFISH_TTY_CMD); 276 270 277 271 ret = request_irq(irq, goldfish_tty_interrupt, IRQF_SHARED, 278 - "goldfish_tty", pdev); 272 + "goldfish_tty", qtty); 279 273 if (ret) 280 274 goto err_request_irq_failed; 281 275 282 276 283 277 ttydev = tty_port_register_device(&qtty->port, goldfish_tty_driver, 284 - pdev->id, &pdev->dev); 278 + line, &pdev->dev); 285 279 if (IS_ERR(ttydev)) { 286 280 ret = PTR_ERR(ttydev); 287 281 goto err_tty_register_device_failed; ··· 292 286 qtty->console.device = goldfish_tty_console_device; 293 287 qtty->console.setup = goldfish_tty_console_setup; 294 288 qtty->console.flags = CON_PRINTBUFFER; 295 - qtty->console.index = pdev->id; 289 + qtty->console.index = line; 296 290 register_console(&qtty->console); 291 + platform_set_drvdata(pdev, qtty); 297 292 298 293 mutex_unlock(&goldfish_tty_lock); 299 294 return 0; ··· 314 307 315 308 static int goldfish_tty_remove(struct platform_device *pdev) 316 309 { 317 - struct goldfish_tty *qtty; 310 + struct goldfish_tty *qtty = platform_get_drvdata(pdev); 318 311 319 312 mutex_lock(&goldfish_tty_lock); 320 313 321 - qtty = &goldfish_ttys[pdev->id]; 322 314 unregister_console(&qtty->console); 323 - tty_unregister_device(goldfish_tty_driver, pdev->id); 315 + tty_unregister_device(goldfish_tty_driver, qtty->console.index); 324 316 iounmap(qtty->base); 325 317 qtty->base = NULL; 326 318 free_irq(qtty->irq, pdev);