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

i2c: convert SMBus alert setup function to return an ERRPTR

Only few drivers use this call, so drivers and I2C core are converted at
once with this patch. By simply using i2c_new_client_device() instead of
i2c_new_device(), we easily can return an ERRPTR for this function as
well. To make out of tree users aware that something changed, the
function is renamed to i2c_new_smbus_alert_device().

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Wolfram Sang and committed by
Wolfram Sang
ed680522 0f820564

+35 -27
+1 -1
Documentation/i2c/smbus-protocol.rst
··· 274 274 This is implemented the following way in the Linux kernel: 275 275 276 276 * I2C bus drivers which support SMBus alert should call 277 - i2c_setup_smbus_alert() to setup SMBus alert support. 277 + i2c_new_smbus_alert_device() to install SMBus alert support. 278 278 * I2C drivers for devices which can trigger SMBus alerts should implement 279 279 the optional alert() callback. 280 280
+8 -4
drivers/i2c/busses/i2c-parport.c
··· 333 333 334 334 /* Setup SMBus alert if supported */ 335 335 if (adapter_parm[type].smbus_alert) { 336 - adapter->ara = i2c_setup_smbus_alert(&adapter->adapter, 337 - &adapter->alert_data); 338 - if (adapter->ara) 336 + struct i2c_client *ara; 337 + 338 + ara = i2c_new_smbus_alert_device(&adapter->adapter, 339 + &adapter->alert_data); 340 + if (!IS_ERR(ara)) { 341 + adapter->ara = ara; 339 342 parport_enable_irq(port); 340 - else 343 + } else { 341 344 dev_warn(&adapter->pdev->dev, 342 345 "Failed to register ARA client\n"); 346 + } 343 347 } 344 348 345 349 /* Add the new adapter to the list */
+8 -3
drivers/i2c/busses/i2c-thunderx-pcidrv.c
··· 118 118 static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, 119 119 struct device_node *node) 120 120 { 121 + struct i2c_client *ara; 122 + 121 123 if (!node) 122 124 return -EINVAL; 123 125 ··· 127 125 if (!i2c->alert_data.irq) 128 126 return -EINVAL; 129 127 130 - i2c->ara = i2c_setup_smbus_alert(&i2c->adap, &i2c->alert_data); 131 - if (!i2c->ara) 132 - return -ENODEV; 128 + ara = i2c_new_smbus_alert_device(&i2c->adap, &i2c->alert_data); 129 + if (IS_ERR(ara)) 130 + return PTR_ERR(ara); 131 + 132 + i2c->ara = ara; 133 + 133 134 return 0; 134 135 } 135 136
+7 -3
drivers/i2c/busses/i2c-xlp9xx.c
··· 491 491 static int xlp9xx_i2c_smbus_setup(struct xlp9xx_i2c_dev *priv, 492 492 struct platform_device *pdev) 493 493 { 494 + struct i2c_client *ara; 495 + 494 496 if (!priv->alert_data.irq) 495 497 return -EINVAL; 496 498 497 - priv->ara = i2c_setup_smbus_alert(&priv->adapter, &priv->alert_data); 498 - if (!priv->ara) 499 - return -ENODEV; 499 + ara = i2c_new_smbus_alert_device(&priv->adapter, &priv->alert_data); 500 + if (IS_ERR(ara)) 501 + return PTR_ERR(ara); 502 + 503 + priv->ara = ara; 500 504 501 505 return 0; 502 506 }
+8 -13
drivers/i2c/i2c-core-smbus.c
··· 666 666 EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated); 667 667 668 668 /** 669 - * i2c_setup_smbus_alert - Setup SMBus alert support 669 + * i2c_new_smbus_alert_device - get ara client for SMBus alert support 670 670 * @adapter: the target adapter 671 671 * @setup: setup data for the SMBus alert handler 672 672 * Context: can sleep ··· 682 682 * should have said it's level triggered. 683 683 * 684 684 * This returns the ara client, which should be saved for later use with 685 - * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL 686 - * to indicate an error. 685 + * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or an 686 + * ERRPTR to indicate an error. 687 687 */ 688 - struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, 689 - struct i2c_smbus_alert_setup *setup) 688 + struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter, 689 + struct i2c_smbus_alert_setup *setup) 690 690 { 691 691 struct i2c_board_info ara_board_info = { 692 692 I2C_BOARD_INFO("smbus_alert", 0x0c), 693 693 .platform_data = setup, 694 694 }; 695 695 696 - return i2c_new_device(adapter, &ara_board_info); 696 + return i2c_new_client_device(adapter, &ara_board_info); 697 697 } 698 - EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); 698 + EXPORT_SYMBOL_GPL(i2c_new_smbus_alert_device); 699 699 700 700 #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) 701 701 int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter) 702 702 { 703 - struct i2c_client *client; 704 703 int irq; 705 704 706 705 irq = of_property_match_string(adapter->dev.of_node, "interrupt-names", ··· 709 710 else if (irq < 0) 710 711 return irq; 711 712 712 - client = i2c_setup_smbus_alert(adapter, NULL); 713 - if (!client) 714 - return -ENODEV; 715 - 716 - return 0; 713 + return PTR_ERR_OR_ZERO(i2c_new_smbus_alert_device(adapter, NULL)); 717 714 } 718 715 EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert); 719 716 #endif
+1 -1
drivers/i2c/i2c-smbus.c
··· 184 184 * corresponding I2C device driver's alert function. 185 185 * 186 186 * It is assumed that ara is a valid i2c client previously returned by 187 - * i2c_setup_smbus_alert(). 187 + * i2c_new_smbus_alert_device(). 188 188 */ 189 189 int i2c_handle_smbus_alert(struct i2c_client *ara) 190 190 {
+2 -2
include/linux/i2c-smbus.h
··· 31 31 int irq; 32 32 }; 33 33 34 - struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, 35 - struct i2c_smbus_alert_setup *setup); 34 + struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter, 35 + struct i2c_smbus_alert_setup *setup); 36 36 int i2c_handle_smbus_alert(struct i2c_client *ara); 37 37 38 38 #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)