Re: [PATCH v4 1/3] mfd: tps6586x: add version detection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 2013-12-05 18:06, schrieb Stephen Warren:
<snip>
>> @@ -493,13 +527,12 @@ static int tps6586x_i2c_probe(struct i2c_client *client,
>>  		return -EIO;
>>  	}
>>
>> -	dev_info(&client->dev, "VERSIONCRC is %02x\n", ret);
>> -
>>  	tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL);
>> -	if (tps6586x == NULL) {
>> -		dev_err(&client->dev, "memory for tps6586x alloc failed\n");
>> +	if (!tps6586x)
>>  		return -ENOMEM;
>> -	}
>> +
>> +	tps6586x->version = ret;
> 
> I have to say, I dislike this version of the patch. Separating the
> reading of the version register from the assignment to tps6586x->version
> doesn't make any sense, especially given that the version value is
> stored in a variable named "ret"; that name isn't remotely related to
> what's stored there. What if someone comes along later and adds more
> code that assigns to ret between where it's repurposed for the version
> value and where it's assigned to tps6586x->version? It'd be extremely
> difficult for a patch reviewer to spot that given the limited context in
> a diff, and quite non-obvious to the person changing the code too..

The value comes from the return value of i2c_smbus_read_byte_data. If
the value is below zero its an EIO error. 

I could add a variable "version", but for me it felt strange because we
check if version is below zero. This feels like its a wrong version
rather than a transmit error. So I would prefer ret over version. But I
agree, when one just reads the patch, its not obvious what exactly
happens.

In v2, I moved the i2c_smbus_read_byte_data function call after the
allocation, so it was more obvious for the reader. But then, as Thierry
Reding pointed out, not moving it is an optimization: In case reading
fails, we don't allocate memory first.
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [ARM Kernel]     [Linux ARM]     [Linux ARM MSM]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux