Skip to content

Commit 6cb31c9

Browse files
committed
i2c: i801: Add helper i801_get_block_len
JIRA: https://issues.redhat.com/browse/RHEL-47426 commit 857cc04 Author: Heiner Kallweit <hkallweit1@gmail.com> Date: Fri Feb 2 08:06:30 2024 +0100 i2c: i801: Add helper i801_get_block_len Avoid code duplication and factor out retrieving and checking the block length value to new helper i801_get_block_len(). Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent f27cfb0 commit 6cb31c9

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
332332
"\t\t 0x10 don't use interrupts\n"
333333
"\t\t 0x20 disable SMBus Host Notify ");
334334

335+
static int i801_get_block_len(struct i801_priv *priv)
336+
{
337+
u8 len = inb_p(SMBHSTDAT0(priv));
338+
339+
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
340+
pci_err(priv->pci_dev, "Illegal SMBus block read size %u\n", len);
341+
return -EPROTO;
342+
}
343+
344+
return len;
345+
}
346+
335347
static int i801_check_and_clear_pec_error(struct i801_priv *priv)
336348
{
337349
u8 status;
@@ -526,12 +538,11 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
526538

527539
if (read_write == I2C_SMBUS_READ ||
528540
command == I2C_SMBUS_BLOCK_PROC_CALL) {
529-
len = inb_p(SMBHSTDAT0(priv));
530-
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
531-
status = -EPROTO;
541+
status = i801_get_block_len(priv);
542+
if (status < 0)
532543
goto out;
533-
}
534544

545+
len = status;
535546
data->block[0] = len;
536547
inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
537548
for (i = 0; i < len; i++)
@@ -551,14 +562,11 @@ static void i801_isr_byte_done(struct i801_priv *priv)
551562
* and read the block length from SMBHSTDAT0.
552563
*/
553564
if (priv->len == SMBUS_LEN_SENTINEL) {
554-
priv->len = inb_p(SMBHSTDAT0(priv));
555-
if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
556-
dev_err(&priv->pci_dev->dev,
557-
"Illegal SMBus block read size %d\n",
558-
priv->len);
565+
priv->len = i801_get_block_len(priv);
566+
if (priv->len < 0)
559567
/* FIXME: Recover */
560568
priv->len = I2C_SMBUS_BLOCK_MAX;
561-
}
569+
562570
priv->data[-1] = priv->len;
563571
}
564572

@@ -715,11 +723,8 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
715723
* and read the block length from SMBHSTDAT0.
716724
*/
717725
if (len == SMBUS_LEN_SENTINEL) {
718-
len = inb_p(SMBHSTDAT0(priv));
719-
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
720-
dev_err(&priv->pci_dev->dev,
721-
"Illegal SMBus block read size %d\n",
722-
len);
726+
len = i801_get_block_len(priv);
727+
if (len < 0) {
723728
/* Recover */
724729
while (inb_p(SMBHSTSTS(priv)) &
725730
SMBHSTSTS_HOST_BUSY)

0 commit comments

Comments
 (0)