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

rtc: bunch of drivers: fix 'no irq' case handing

This patch fixes a bunch of irq checking misuses. Most drivers were
getting irq via platform_get_irq(), which returns -ENXIO or r->start.

rtc-cmos.c is special. It is using PNP and platform bindings. Hopefully
nobody is using PNP IRQ 0 for RTC. So the changes should be safe.

rtc-sh.c is using platform_get_irq, but was storing a result into an
unsigned type, then was checking for < 0. This is fixed now.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Anton Vorontsov and committed by
Linus Torvalds
2fac6674 d4afc76c

+40 -40
+2 -2
drivers/rtc/rtc-at32ap700x.c
··· 205 205 { 206 206 struct resource *regs; 207 207 struct rtc_at32ap700x *rtc; 208 - int irq = -1; 208 + int irq; 209 209 int ret; 210 210 211 211 rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL); ··· 222 222 } 223 223 224 224 irq = platform_get_irq(pdev, 0); 225 - if (irq < 0) { 225 + if (irq <= 0) { 226 226 dev_dbg(&pdev->dev, "could not get irq\n"); 227 227 ret = -ENXIO; 228 228 goto out;
+1 -1
drivers/rtc/rtc-cmos.c
··· 58 58 }; 59 59 60 60 /* both platform and pnp busses use negative numbers for invalid irqs */ 61 - #define is_valid_irq(n) ((n) >= 0) 61 + #define is_valid_irq(n) ((n) > 0) 62 62 63 63 static const char driver_name[] = "rtc_cmos"; 64 64
+9 -10
drivers/rtc/rtc-ds1511.c
··· 326 326 struct platform_device *pdev = to_platform_device(dev); 327 327 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 328 328 329 - if (pdata->irq < 0) { 329 + if (pdata->irq <= 0) 330 330 return -EINVAL; 331 - } 331 + 332 332 pdata->alrm_mday = alrm->time.tm_mday; 333 333 pdata->alrm_hour = alrm->time.tm_hour; 334 334 pdata->alrm_min = alrm->time.tm_min; ··· 346 346 struct platform_device *pdev = to_platform_device(dev); 347 347 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 348 348 349 - if (pdata->irq < 0) { 349 + if (pdata->irq <= 0) 350 350 return -EINVAL; 351 - } 351 + 352 352 alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; 353 353 alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; 354 354 alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min; ··· 385 385 struct platform_device *pdev = to_platform_device(dev); 386 386 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 387 387 388 - if (pdata->irq < 0) { 388 + if (pdata->irq <= 0) { 389 389 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 390 390 } 391 391 switch (cmd) { ··· 503 503 if (!pdata) { 504 504 return -ENOMEM; 505 505 } 506 - pdata->irq = -1; 507 506 pdata->size = res->end - res->start + 1; 508 507 if (!request_mem_region(res->start, pdata->size, pdev->name)) { 509 508 ret = -EBUSY; ··· 544 545 * if the platform has an interrupt in mind for this device, 545 546 * then by all means, set it 546 547 */ 547 - if (pdata->irq >= 0) { 548 + if (pdata->irq > 0) { 548 549 rtc_read(RTC_CMD1); 549 550 if (request_irq(pdata->irq, ds1511_interrupt, 550 551 IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) { 551 552 552 553 dev_warn(&pdev->dev, "interrupt not available.\n"); 553 - pdata->irq = -1; 554 + pdata->irq = 0; 554 555 } 555 556 } 556 557 ··· 571 572 if (pdata->rtc) { 572 573 rtc_device_unregister(pdata->rtc); 573 574 } 574 - if (pdata->irq >= 0) { 575 + if (pdata->irq > 0) { 575 576 free_irq(pdata->irq, pdev); 576 577 } 577 578 if (ds1511_base) { ··· 594 595 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 595 596 rtc_device_unregister(pdata->rtc); 596 597 pdata->rtc = NULL; 597 - if (pdata->irq >= 0) { 598 + if (pdata->irq > 0) { 598 599 /* 599 600 * disable the alarm interrupt 600 601 */
+7 -8
drivers/rtc/rtc-ds1553.c
··· 162 162 struct platform_device *pdev = to_platform_device(dev); 163 163 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 164 164 165 - if (pdata->irq < 0) 165 + if (pdata->irq <= 0) 166 166 return -EINVAL; 167 167 pdata->alrm_mday = alrm->time.tm_mday; 168 168 pdata->alrm_hour = alrm->time.tm_hour; ··· 179 179 struct platform_device *pdev = to_platform_device(dev); 180 180 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 181 181 182 - if (pdata->irq < 0) 182 + if (pdata->irq <= 0) 183 183 return -EINVAL; 184 184 alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; 185 185 alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; ··· 213 213 struct platform_device *pdev = to_platform_device(dev); 214 214 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 215 215 216 - if (pdata->irq < 0) 216 + if (pdata->irq <= 0) 217 217 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 218 218 switch (cmd) { 219 219 case RTC_AIE_OFF: ··· 301 301 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 302 302 if (!pdata) 303 303 return -ENOMEM; 304 - pdata->irq = -1; 305 304 if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) { 306 305 ret = -EBUSY; 307 306 goto out; ··· 326 327 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_BLF) 327 328 dev_warn(&pdev->dev, "voltage-low detected.\n"); 328 329 329 - if (pdata->irq >= 0) { 330 + if (pdata->irq > 0) { 330 331 writeb(0, ioaddr + RTC_INTERRUPTS); 331 332 if (request_irq(pdata->irq, ds1553_rtc_interrupt, 332 333 IRQF_DISABLED | IRQF_SHARED, 333 334 pdev->name, pdev) < 0) { 334 335 dev_warn(&pdev->dev, "interrupt not available.\n"); 335 - pdata->irq = -1; 336 + pdata->irq = 0; 336 337 } 337 338 } 338 339 ··· 352 353 out: 353 354 if (pdata->rtc) 354 355 rtc_device_unregister(pdata->rtc); 355 - if (pdata->irq >= 0) 356 + if (pdata->irq > 0) 356 357 free_irq(pdata->irq, pdev); 357 358 if (ioaddr) 358 359 iounmap(ioaddr); ··· 368 369 369 370 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 370 371 rtc_device_unregister(pdata->rtc); 371 - if (pdata->irq >= 0) { 372 + if (pdata->irq > 0) { 372 373 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 373 374 free_irq(pdata->irq, pdev); 374 375 }
+1 -1
drivers/rtc/rtc-m48t59.c
··· 450 450 * the mode without IRQ. 451 451 */ 452 452 m48t59->irq = platform_get_irq(pdev, 0); 453 - if (m48t59->irq < 0) 453 + if (m48t59->irq <= 0) 454 454 m48t59->irq = NO_IRQ; 455 455 456 456 if (m48t59->irq != NO_IRQ) {
+6 -4
drivers/rtc/rtc-sh.c
··· 89 89 void __iomem *regbase; 90 90 unsigned long regsize; 91 91 struct resource *res; 92 - unsigned int alarm_irq, periodic_irq, carry_irq; 92 + int alarm_irq; 93 + int periodic_irq; 94 + int carry_irq; 93 95 struct rtc_device *rtc_dev; 94 96 spinlock_t lock; 95 97 unsigned long capabilities; /* See asm-sh/rtc.h for cap bits */ ··· 580 578 581 579 /* get periodic/carry/alarm irqs */ 582 580 ret = platform_get_irq(pdev, 0); 583 - if (unlikely(ret < 0)) { 581 + if (unlikely(ret <= 0)) { 584 582 ret = -ENOENT; 585 583 dev_err(&pdev->dev, "No IRQ for period\n"); 586 584 goto err_badres; ··· 588 586 rtc->periodic_irq = ret; 589 587 590 588 ret = platform_get_irq(pdev, 1); 591 - if (unlikely(ret < 0)) { 589 + if (unlikely(ret <= 0)) { 592 590 ret = -ENOENT; 593 591 dev_err(&pdev->dev, "No IRQ for carry\n"); 594 592 goto err_badres; ··· 596 594 rtc->carry_irq = ret; 597 595 598 596 ret = platform_get_irq(pdev, 2); 599 - if (unlikely(ret < 0)) { 597 + if (unlikely(ret <= 0)) { 600 598 ret = -ENOENT; 601 599 dev_err(&pdev->dev, "No IRQ for alarm\n"); 602 600 goto err_badres;
+7 -8
drivers/rtc/rtc-stk17ta8.c
··· 170 170 struct platform_device *pdev = to_platform_device(dev); 171 171 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 172 172 173 - if (pdata->irq < 0) 173 + if (pdata->irq <= 0) 174 174 return -EINVAL; 175 175 pdata->alrm_mday = alrm->time.tm_mday; 176 176 pdata->alrm_hour = alrm->time.tm_hour; ··· 187 187 struct platform_device *pdev = to_platform_device(dev); 188 188 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 189 189 190 - if (pdata->irq < 0) 190 + if (pdata->irq <= 0) 191 191 return -EINVAL; 192 192 alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; 193 193 alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; ··· 221 221 struct platform_device *pdev = to_platform_device(dev); 222 222 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 223 223 224 - if (pdata->irq < 0) 224 + if (pdata->irq <= 0) 225 225 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */ 226 226 switch (cmd) { 227 227 case RTC_AIE_OFF: ··· 303 303 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 304 304 if (!pdata) 305 305 return -ENOMEM; 306 - pdata->irq = -1; 307 306 if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) { 308 307 ret = -EBUSY; 309 308 goto out; ··· 328 329 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF) 329 330 dev_warn(&pdev->dev, "voltage-low detected.\n"); 330 331 331 - if (pdata->irq >= 0) { 332 + if (pdata->irq > 0) { 332 333 writeb(0, ioaddr + RTC_INTERRUPTS); 333 334 if (request_irq(pdata->irq, stk17ta8_rtc_interrupt, 334 335 IRQF_DISABLED | IRQF_SHARED, 335 336 pdev->name, pdev) < 0) { 336 337 dev_warn(&pdev->dev, "interrupt not available.\n"); 337 - pdata->irq = -1; 338 + pdata->irq = 0; 338 339 } 339 340 } 340 341 ··· 354 355 out: 355 356 if (pdata->rtc) 356 357 rtc_device_unregister(pdata->rtc); 357 - if (pdata->irq >= 0) 358 + if (pdata->irq > 0) 358 359 free_irq(pdata->irq, pdev); 359 360 if (ioaddr) 360 361 iounmap(ioaddr); ··· 370 371 371 372 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 372 373 rtc_device_unregister(pdata->rtc); 373 - if (pdata->irq >= 0) { 374 + if (pdata->irq > 0) { 374 375 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 375 376 free_irq(pdata->irq, pdev); 376 377 }
+3 -2
drivers/rtc/rtc-twl4030.c
··· 19 19 */ 20 20 21 21 #include <linux/kernel.h> 22 + #include <linux/errno.h> 22 23 #include <linux/init.h> 23 24 #include <linux/module.h> 24 25 #include <linux/types.h> ··· 416 415 int irq = platform_get_irq(pdev, 0); 417 416 u8 rd_reg; 418 417 419 - if (irq < 0) 420 - return irq; 418 + if (irq <= 0) 419 + return -EINVAL; 421 420 422 421 rtc = rtc_device_register(pdev->name, 423 422 &pdev->dev, &twl4030_rtc_ops, THIS_MODULE);
+4 -4
drivers/rtc/rtc-vr41xx.c
··· 84 84 static char rtc_name[] = "RTC"; 85 85 static unsigned long periodic_count; 86 86 static unsigned int alarm_enabled; 87 - static int aie_irq = -1; 88 - static int pie_irq = -1; 87 + static int aie_irq; 88 + static int pie_irq; 89 89 90 90 static inline unsigned long read_elapsed_second(void) 91 91 { ··· 360 360 spin_unlock_irq(&rtc_lock); 361 361 362 362 aie_irq = platform_get_irq(pdev, 0); 363 - if (aie_irq < 0 || aie_irq >= nr_irqs) { 363 + if (aie_irq <= 0) { 364 364 retval = -EBUSY; 365 365 goto err_device_unregister; 366 366 } ··· 371 371 goto err_device_unregister; 372 372 373 373 pie_irq = platform_get_irq(pdev, 1); 374 - if (pie_irq < 0 || pie_irq >= nr_irqs) 374 + if (pie_irq <= 0) 375 375 goto err_free_irq; 376 376 377 377 retval = request_irq(pie_irq, rtclong1_interrupt, IRQF_DISABLED,