[v4,1/2] staging: most: dim2: read done_buffers count locally from HDM channel

Message ID 83fd237d2ac157d234e9c7cce1206904c2d8773d.1666208065.git.drv@mailo.com
State New
Headers
Series staging: most: dim2: remove unnecessary function call and variable usage |

Commit Message

Deepak R Varma Oct. 19, 2022, 7:54 p.m. UTC
  The function dim_get_channel_state only serves to initialize the ready and
done_buffers fields of the structure passed as its second argument. In
service_done_flag, this structure is never used again and the only purpose
of the call is to get the value that is put in the done_buffers field.
But that value is just the done_sw_buffers_number field of the call's
first argument.  So the whole call is useless, and we can just replace it
with an access to this field.

This change implies that the variable st is no longer used, so drop it as
well.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---

PLEASE NOTE:
   1. I have only built the module on my machine, but have not tested it.
      I am not sure how to test this change. I am willing to test it with
      appropriate guidance provided I have the necessary hardware.
   2. This was a standalone patch earlier. It is now combined into a patch set
      with another patch for the same driver. Hence I am carry forwarding the
      change log for this patch here:

Changes in v4:
   -- None.

Changes in v3:
   1. The patch log message is further improved. This revised verbiage is as
      thankfully provided by julia.lawall@inria.fr

Changes in v2:
   1. Update patch log message to be more descriptive about the reason for change.
      Feedback provided by julia.lawall@inria.fr


 drivers/staging/most/dim2/dim2.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--
2.30.2
  

Comments

Greg KH Oct. 20, 2022, 3:03 p.m. UTC | #1
On Thu, Oct 20, 2022 at 01:24:53AM +0530, Deepak R Varma wrote:
> The function dim_get_channel_state only serves to initialize the ready and
> done_buffers fields of the structure passed as its second argument. In
> service_done_flag, this structure is never used again and the only purpose
> of the call is to get the value that is put in the done_buffers field.
> But that value is just the done_sw_buffers_number field of the call's
> first argument.  So the whole call is useless, and we can just replace it
> with an access to this field.

Are you sure it is useless?

You have changed the logic here, you are now thinking that this value
can never change, while before you were ensured of getting the "correct"
value as it is under the lock when the function is called.

I can't take this type of change as a "cleanup" patch for outreachy
unless you have the hardware as it is NOT a basic "checkpatch" style
cleanup at all.

If you want to get this change accepted, please work with the maintainer
of the code and get them to agree that the change is correct.  And if it
is, odds are more things also would need to be cleaned up at the same
time, right?

thanks,

greg k-h
  
Deepak R Varma Oct. 20, 2022, 4:41 p.m. UTC | #2
On Thu, Oct 20, 2022 at 05:03:14PM +0200, Greg KH wrote:
> On Thu, Oct 20, 2022 at 01:24:53AM +0530, Deepak R Varma wrote:
> > The function dim_get_channel_state only serves to initialize the ready and
> > done_buffers fields of the structure passed as its second argument. In
> > service_done_flag, this structure is never used again and the only purpose
> > of the call is to get the value that is put in the done_buffers field.
> > But that value is just the done_sw_buffers_number field of the call's
> > first argument.  So the whole call is useless, and we can just replace it
> > with an access to this field.
>
> Are you sure it is useless?

Hello,
pardon my limited understanding, but I think this function call is not
necessary.

>
> You have changed the logic here, you are now thinking that this value
> can never change, while before you were ensured of getting the "correct"
> value as it is under the lock when the function is called.

I may be wrong, but I do not think there is a change in the long, but I may
entirely wrong. The function was called from inside the lock scope, now we are
extracting the value directly, still inside the lock scope. This should be safe.

>
> I can't take this type of change as a "cleanup" patch for outreachy
> unless you have the hardware as it is NOT a basic "checkpatch" style
> cleanup at all.

Sure. That is fine.

>
> If you want to get this change accepted, please work with the maintainer
> of the code and get them to agree that the change is correct.  And if it
> is, odds are more things also would need to be cleaned up at the same
> time, right?

I am eagerly waiting for a feedback from the maintainer. If they agree with my
viewpoint, I will continue to work on this change outside of the clean up patch
tasks. I will be happy to :)

Thank you Greg!
./drv

>
> thanks,
>
> greg k-h
>
  

Patch

diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index ab72e11ac5ab..4c1f27898a29 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -259,7 +259,6 @@  static void retrieve_netinfo(struct dim2_hdm *dev, struct mbo *mbo)
 static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
 {
 	struct hdm_channel *hdm_ch = dev->hch + ch_idx;
-	struct dim_ch_state_t st;
 	struct list_head *head;
 	struct mbo *mbo;
 	int done_buffers;
@@ -271,7 +270,7 @@  static void service_done_flag(struct dim2_hdm *dev, int ch_idx)

 	spin_lock_irqsave(&dim_lock, flags);

-	done_buffers = dim_get_channel_state(&hdm_ch->ch, &st)->done_buffers;
+	done_buffers = hdm_ch->ch.done_sw_buffers_number;
 	if (!done_buffers) {
 		spin_unlock_irqrestore(&dim_lock, flags);
 		return;