diff mbox series

[v4,16/31] i2c: tegra: Remove "dma" variable from tegra_i2c_xfer_msg()

Message ID 20200905204151.25343-17-digetx@gmail.com
State Superseded
Headers show
Series Improvements for Tegra I2C driver | expand

Commit Message

Dmitry Osipenko Sept. 5, 2020, 8:41 p.m. UTC
The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in
regards to readability and generation of the code, hence let's remove it
to clean up code a tad.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/i2c/busses/i2c-tegra.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Comments

Michał Mirosław Sept. 5, 2020, 10:23 p.m. UTC | #1
On Sat, Sep 05, 2020 at 11:41:36PM +0300, Dmitry Osipenko wrote:
> The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in
> regards to readability and generation of the code, hence let's remove it
> to clean up code a tad.
[...]
> --- a/drivers/i2c/busses/i2c-tegra.c
> +++ b/drivers/i2c/busses/i2c-tegra.c
[...]
> +	if (i2c_dev->is_curr_dma_xfer) {
[...]

In this case I like the previous code better: just because there are
less letters to read. :-)

Best Regards,
Michał Mirosław
Dmitry Osipenko Sept. 5, 2020, 10:36 p.m. UTC | #2
06.09.2020 01:23, Michał Mirosław пишет:
> On Sat, Sep 05, 2020 at 11:41:36PM +0300, Dmitry Osipenko wrote:
>> The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in
>> regards to readability and generation of the code, hence let's remove it
>> to clean up code a tad.
> [...]
>> --- a/drivers/i2c/busses/i2c-tegra.c
>> +++ b/drivers/i2c/busses/i2c-tegra.c
> [...]
>> +	if (i2c_dev->is_curr_dma_xfer) {
> [...]
> 
> In this case I like the previous code better: just because there are
> less letters to read. :-)

Besides readability, I also don't like much that the is_curr_dma_xfer is
initialized in tegra_i2c_xfer_msg() and then could be overridden by
tegra_i2c_config_fifo_trig(). In a result the "dma" variable confuses me
since it's not instantly obvious why it's set after
tegra_i2c_config_fifo_trig().

Looking at the final result, I think it's better to have the variable
removed. It makes code more consistent, IMO.
Michał Mirosław Sept. 5, 2020, 10:49 p.m. UTC | #3
On Sun, Sep 06, 2020 at 01:36:20AM +0300, Dmitry Osipenko wrote:
> 06.09.2020 01:23, Michał Mirosław пишет:
> > On Sat, Sep 05, 2020 at 11:41:36PM +0300, Dmitry Osipenko wrote:
> >> The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in
> >> regards to readability and generation of the code, hence let's remove it
> >> to clean up code a tad.
> > [...]
> >> --- a/drivers/i2c/busses/i2c-tegra.c
> >> +++ b/drivers/i2c/busses/i2c-tegra.c
> > [...]
> >> +	if (i2c_dev->is_curr_dma_xfer) {
> > [...]
> > 
> > In this case I like the previous code better: just because there are
> > less letters to read. :-)
> 
> Besides readability, I also don't like much that the is_curr_dma_xfer is
> initialized in tegra_i2c_xfer_msg() and then could be overridden by
> tegra_i2c_config_fifo_trig(). In a result the "dma" variable confuses me
> since it's not instantly obvious why it's set after
> tegra_i2c_config_fifo_trig().
> 
> Looking at the final result, I think it's better to have the variable
> removed. It makes code more consistent, IMO.

If it could be changed in some callee, then indeed it is better. In this
case I would include this information in the commit msg.

Best Regards,
Michał Mirosław
Dmitry Osipenko Sept. 5, 2020, 10:54 p.m. UTC | #4
06.09.2020 01:49, Michał Mirosław пишет:
> On Sun, Sep 06, 2020 at 01:36:20AM +0300, Dmitry Osipenko wrote:
>> 06.09.2020 01:23, Michał Mirosław пишет:
>>> On Sat, Sep 05, 2020 at 11:41:36PM +0300, Dmitry Osipenko wrote:
>>>> The "dma" variable of tegra_i2c_xfer_msg() function doesn't bring much in
>>>> regards to readability and generation of the code, hence let's remove it
>>>> to clean up code a tad.
>>> [...]
>>>> --- a/drivers/i2c/busses/i2c-tegra.c
>>>> +++ b/drivers/i2c/busses/i2c-tegra.c
>>> [...]
>>>> +	if (i2c_dev->is_curr_dma_xfer) {
>>> [...]
>>>
>>> In this case I like the previous code better: just because there are
>>> less letters to read. :-)
>>
>> Besides readability, I also don't like much that the is_curr_dma_xfer is
>> initialized in tegra_i2c_xfer_msg() and then could be overridden by
>> tegra_i2c_config_fifo_trig(). In a result the "dma" variable confuses me
>> since it's not instantly obvious why it's set after
>> tegra_i2c_config_fifo_trig().
>>
>> Looking at the final result, I think it's better to have the variable
>> removed. It makes code more consistent, IMO.
> 
> If it could be changed in some callee, then indeed it is better. In this
> case I would include this information in the commit msg.

That's a good suggestion, thanks.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index f69587ca163b..f52046593b8b 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1155,7 +1155,6 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 	size_t xfer_size;
 	u32 *buffer = NULL;
 	int err = 0;
-	bool dma;
 	u16 xfer_time = 100;
 
 	err = tegra_i2c_flush_fifos(i2c_dev);
@@ -1178,7 +1177,7 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 				    i2c_dev->dma_buf &&
 				    !i2c_dev->is_curr_atomic_xfer;
 	tegra_i2c_config_fifo_trig(i2c_dev, xfer_size);
-	dma = i2c_dev->is_curr_dma_xfer;
+
 	/*
 	 * Transfer time in mSec = Total bits / transfer rate
 	 * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits
@@ -1188,7 +1187,7 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 
 	int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST;
 	tegra_i2c_unmask_irq(i2c_dev, int_mask);
-	if (dma) {
+	if (i2c_dev->is_curr_dma_xfer) {
 		if (i2c_dev->msg_read) {
 			dma_sync_single_for_device(i2c_dev->dev,
 						   i2c_dev->dma_phys,
@@ -1216,13 +1215,13 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 				   PACKET_HEADER0_PROTOCOL_I2C) |
 			FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) |
 			FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1);
-	if (dma && !i2c_dev->msg_read)
+	if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read)
 		*buffer++ = packet_header;
 	else
 		i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
 
 	packet_header = msg->len - 1;
-	if (dma && !i2c_dev->msg_read)
+	if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read)
 		*buffer++ = packet_header;
 	else
 		i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
@@ -1242,13 +1241,13 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 		packet_header |= I2C_HEADER_CONT_ON_NAK;
 	if (msg->flags & I2C_M_RD)
 		packet_header |= I2C_HEADER_READ;
-	if (dma && !i2c_dev->msg_read)
+	if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read)
 		*buffer++ = packet_header;
 	else
 		i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
 
 	if (!i2c_dev->msg_read) {
-		if (dma) {
+		if (i2c_dev->is_curr_dma_xfer) {
 			memcpy(buffer, msg->buf, msg->len);
 			dma_sync_single_for_device(i2c_dev->dev,
 						   i2c_dev->dma_phys,
@@ -1268,7 +1267,7 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 
 	if (i2c_dev->hw->has_per_pkt_xfer_complete_irq)
 		int_mask |= I2C_INT_PACKET_XFER_COMPLETE;
-	if (!dma) {
+	if (!i2c_dev->is_curr_dma_xfer) {
 		if (msg->flags & I2C_M_RD)
 			int_mask |= I2C_INT_RX_FIFO_DATA_REQ;
 		else if (i2c_dev->msg_buf_remaining)
@@ -1279,7 +1278,7 @@  static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 	dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n",
 		i2c_readl(i2c_dev, I2C_INT_MASK));
 
-	if (dma) {
+	if (i2c_dev->is_curr_dma_xfer) {
 		time_left = tegra_i2c_wait_completion_timeout(
 				i2c_dev, &i2c_dev->dma_complete, xfer_time);