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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c bugfixes from Wolfram Sang:
"I2C driver bugfixes for the 3.17 release. Details can be found in the
commit messages, yet I think this is typical driver stuff"

* 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
Revert "i2c: rcar: remove spinlock"
i2c: at91: add bound checking on SMBus block length bytes
i2c: rk3x: fix bug that cause transfer fails in master receive mode
i2c: at91: Fix a race condition during signal handling in at91_do_twi_xfer.
i2c: mv64xxx: continue probe when clock-frequency is missing
i2c: rcar: fix MNR interrupt handling

+62 -14
+26 -6
drivers/i2c/busses/i2c-at91.c
··· 101 101 unsigned twi_cwgr_reg; 102 102 struct at91_twi_pdata *pdata; 103 103 bool use_dma; 104 + bool recv_len_abort; 104 105 struct at91_twi_dma dma; 105 106 }; 106 107 ··· 268 267 *dev->buf = at91_twi_read(dev, AT91_TWI_RHR) & 0xff; 269 268 --dev->buf_len; 270 269 270 + /* return if aborting, we only needed to read RHR to clear RXRDY*/ 271 + if (dev->recv_len_abort) 272 + return; 273 + 271 274 /* handle I2C_SMBUS_BLOCK_DATA */ 272 275 if (unlikely(dev->msg->flags & I2C_M_RECV_LEN)) { 273 - dev->msg->flags &= ~I2C_M_RECV_LEN; 274 - dev->buf_len += *dev->buf; 275 - dev->msg->len = dev->buf_len + 1; 276 - dev_dbg(dev->dev, "received block length %d\n", dev->buf_len); 276 + /* ensure length byte is a valid value */ 277 + if (*dev->buf <= I2C_SMBUS_BLOCK_MAX && *dev->buf > 0) { 278 + dev->msg->flags &= ~I2C_M_RECV_LEN; 279 + dev->buf_len += *dev->buf; 280 + dev->msg->len = dev->buf_len + 1; 281 + dev_dbg(dev->dev, "received block length %d\n", 282 + dev->buf_len); 283 + } else { 284 + /* abort and send the stop by reading one more byte */ 285 + dev->recv_len_abort = true; 286 + dev->buf_len = 1; 287 + } 277 288 } 278 289 279 290 /* send stop if second but last byte has been read */ ··· 434 421 } 435 422 } 436 423 437 - ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 438 - dev->adapter.timeout); 424 + ret = wait_for_completion_io_timeout(&dev->cmd_complete, 425 + dev->adapter.timeout); 439 426 if (ret == 0) { 440 427 dev_err(dev->dev, "controller timed out\n"); 441 428 at91_init_twi_bus(dev); ··· 457 444 ret = -EIO; 458 445 goto error; 459 446 } 447 + if (dev->recv_len_abort) { 448 + dev_err(dev->dev, "invalid smbus block length recvd\n"); 449 + ret = -EPROTO; 450 + goto error; 451 + } 452 + 460 453 dev_dbg(dev->dev, "transfer complete\n"); 461 454 462 455 return 0; ··· 519 500 dev->buf_len = m_start->len; 520 501 dev->buf = m_start->buf; 521 502 dev->msg = m_start; 503 + dev->recv_len_abort = false; 522 504 523 505 ret = at91_do_twi_transfer(dev); 524 506
+1 -2
drivers/i2c/busses/i2c-mv64xxx.c
··· 746 746 } 747 747 tclk = clk_get_rate(drv_data->clk); 748 748 749 - rc = of_property_read_u32(np, "clock-frequency", &bus_freq); 750 - if (rc) 749 + if (of_property_read_u32(np, "clock-frequency", &bus_freq)) 751 750 bus_freq = 100000; /* 100kHz by default */ 752 751 753 752 if (!mv64xxx_find_baud_factors(bus_freq, tclk,
+31 -6
drivers/i2c/busses/i2c-rcar.c
··· 34 34 #include <linux/platform_device.h> 35 35 #include <linux/pm_runtime.h> 36 36 #include <linux/slab.h> 37 + #include <linux/spinlock.h> 37 38 38 39 /* register offsets */ 39 40 #define ICSCR 0x00 /* slave ctrl */ ··· 96 95 struct i2c_msg *msg; 97 96 struct clk *clk; 98 97 98 + spinlock_t lock; 99 99 wait_queue_head_t wait; 100 100 101 101 int pos; ··· 367 365 struct rcar_i2c_priv *priv = ptr; 368 366 u32 msr; 369 367 368 + /*-------------- spin lock -----------------*/ 369 + spin_lock(&priv->lock); 370 + 370 371 msr = rcar_i2c_read(priv, ICMSR); 372 + 373 + /* Only handle interrupts that are currently enabled */ 374 + msr &= rcar_i2c_read(priv, ICMIER); 371 375 372 376 /* Arbitration lost */ 373 377 if (msr & MAL) { 374 378 rcar_i2c_flags_set(priv, (ID_DONE | ID_ARBLOST)); 375 - goto out; 376 - } 377 - 378 - /* Stop */ 379 - if (msr & MST) { 380 - rcar_i2c_flags_set(priv, ID_DONE); 381 379 goto out; 382 380 } 383 381 ··· 387 385 rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_STOP); 388 386 rcar_i2c_write(priv, ICMIER, RCAR_IRQ_STOP); 389 387 rcar_i2c_flags_set(priv, ID_NACK); 388 + goto out; 389 + } 390 + 391 + /* Stop */ 392 + if (msr & MST) { 393 + rcar_i2c_flags_set(priv, ID_DONE); 390 394 goto out; 391 395 } 392 396 ··· 408 400 wake_up(&priv->wait); 409 401 } 410 402 403 + spin_unlock(&priv->lock); 404 + /*-------------- spin unlock -----------------*/ 405 + 411 406 return IRQ_HANDLED; 412 407 } 413 408 ··· 420 409 { 421 410 struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); 422 411 struct device *dev = rcar_i2c_priv_to_dev(priv); 412 + unsigned long flags; 423 413 int i, ret, timeout; 424 414 425 415 pm_runtime_get_sync(dev); 426 416 417 + /*-------------- spin lock -----------------*/ 418 + spin_lock_irqsave(&priv->lock, flags); 419 + 427 420 rcar_i2c_init(priv); 428 421 /* start clock */ 429 422 rcar_i2c_write(priv, ICCCR, priv->icccr); 423 + 424 + spin_unlock_irqrestore(&priv->lock, flags); 425 + /*-------------- spin unlock -----------------*/ 430 426 431 427 ret = rcar_i2c_bus_barrier(priv); 432 428 if (ret < 0) ··· 446 428 break; 447 429 } 448 430 431 + /*-------------- spin lock -----------------*/ 432 + spin_lock_irqsave(&priv->lock, flags); 433 + 449 434 /* init each data */ 450 435 priv->msg = &msgs[i]; 451 436 priv->pos = 0; ··· 457 436 rcar_i2c_flags_set(priv, ID_LAST_MSG); 458 437 459 438 ret = rcar_i2c_prepare_msg(priv); 439 + 440 + spin_unlock_irqrestore(&priv->lock, flags); 441 + /*-------------- spin unlock -----------------*/ 460 442 461 443 if (ret < 0) 462 444 break; ··· 564 540 565 541 irq = platform_get_irq(pdev, 0); 566 542 init_waitqueue_head(&priv->wait); 543 + spin_lock_init(&priv->lock); 567 544 568 545 adap = &priv->adap; 569 546 adap->nr = pdev->id;
+4
drivers/i2c/busses/i2c-rk3x.c
··· 323 323 /* ack interrupt */ 324 324 i2c_writel(i2c, REG_INT_MBRF, REG_IPD); 325 325 326 + /* Can only handle a maximum of 32 bytes at a time */ 327 + if (len > 32) 328 + len = 32; 329 + 326 330 /* read the data from receive buffer */ 327 331 for (i = 0; i < len; ++i) { 328 332 if (i % 4 == 0)