All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] lib: bpf_glue: remove useless assignment
@ 2021-08-07 16:58 Andrea Claudi
  2021-08-11  3:00 ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Claudi @ 2021-08-07 16:58 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern, haliu

The value of s used inside the cycle is the result of strstr(), so this
assignment is useless.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
 lib/bpf_glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c
index eaa9504f..70d00184 100644
--- a/lib/bpf_glue.c
+++ b/lib/bpf_glue.c
@@ -63,7 +63,7 @@ const char *get_libbpf_version(void)
 	if (fp == NULL)
 		goto out;
 
-	while ((s = fgets(buf, sizeof(buf), fp)) != NULL) {
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		if ((s = strstr(buf, "libbpf.so.")) != NULL) {
 			strncpy(_libbpf_version, s+10, sizeof(_libbpf_version)-1);
 			strtok(_libbpf_version, "\n");
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] lib: bpf_glue: remove useless assignment
  2021-08-07 16:58 [PATCH iproute2] lib: bpf_glue: remove useless assignment Andrea Claudi
@ 2021-08-11  3:00 ` Stephen Hemminger
  2021-08-11  9:12   ` Andrea Claudi
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2021-08-11  3:00 UTC (permalink / raw)
  To: Andrea Claudi; +Cc: netdev, dsahern, haliu

On Sat,  7 Aug 2021 18:58:02 +0200
Andrea Claudi <aclaudi@redhat.com> wrote:

> -	while ((s = fgets(buf, sizeof(buf), fp)) != NULL) {
> +	while (fgets(buf, sizeof(buf), fp) != NULL) {
>  		if ((s = strstr(buf, "libbpf.so.")) != NULL) {

Ok. but it would be good to get rid of the unnecessary assignment in conditional as well.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] lib: bpf_glue: remove useless assignment
  2021-08-11  3:00 ` Stephen Hemminger
@ 2021-08-11  9:12   ` Andrea Claudi
  2021-08-11 16:08     ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Claudi @ 2021-08-11  9:12 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, dsahern, haliu

On Tue, Aug 10, 2021 at 08:00:48PM -0700, Stephen Hemminger wrote:
> On Sat,  7 Aug 2021 18:58:02 +0200
> Andrea Claudi <aclaudi@redhat.com> wrote:
> 
> > -	while ((s = fgets(buf, sizeof(buf), fp)) != NULL) {
> > +	while (fgets(buf, sizeof(buf), fp) != NULL) {
> >  		if ((s = strstr(buf, "libbpf.so.")) != NULL) {
> 
> Ok. but it would be good to get rid of the unnecessary assignment in conditional as well.
> 
Hi Stephen,
That's not unnecessary, s is used as the second parameter in the following strncpy().


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] lib: bpf_glue: remove useless assignment
  2021-08-11  9:12   ` Andrea Claudi
@ 2021-08-11 16:08     ` Stephen Hemminger
  2021-08-12  9:01       ` Andrea Claudi
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2021-08-11 16:08 UTC (permalink / raw)
  To: Andrea Claudi; +Cc: netdev, dsahern, haliu

On Wed, 11 Aug 2021 11:12:43 +0200
Andrea Claudi <aclaudi@redhat.com> wrote:

> On Tue, Aug 10, 2021 at 08:00:48PM -0700, Stephen Hemminger wrote:
> > On Sat,  7 Aug 2021 18:58:02 +0200
> > Andrea Claudi <aclaudi@redhat.com> wrote:
> >   
> > > -	while ((s = fgets(buf, sizeof(buf), fp)) != NULL) {
> > > +	while (fgets(buf, sizeof(buf), fp) != NULL) {
> > >  		if ((s = strstr(buf, "libbpf.so.")) != NULL) {  
> > 
> > Ok. but it would be good to get rid of the unnecessary assignment in conditional as well.
> >   
> Hi Stephen,
> That's not unnecessary, s is used as the second parameter in the following strncpy().
> 


It is bad style in C to do assignment in a conditional.
It causes errors, and is not anymore efficient.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] lib: bpf_glue: remove useless assignment
  2021-08-11 16:08     ` Stephen Hemminger
@ 2021-08-12  9:01       ` Andrea Claudi
  2021-08-12 16:26         ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Claudi @ 2021-08-12  9:01 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, dsahern, haliu

On Wed, Aug 11, 2021 at 09:08:15AM -0700, Stephen Hemminger wrote:
> It is bad style in C to do assignment in a conditional.
> It causes errors, and is not anymore efficient.
> 
I agree with you.

There is a large number of similar assignments in other parts of the
code; I can work on a treewide patch to address them all, if you think
it's a good idea.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] lib: bpf_glue: remove useless assignment
  2021-08-12  9:01       ` Andrea Claudi
@ 2021-08-12 16:26         ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2021-08-12 16:26 UTC (permalink / raw)
  To: Andrea Claudi; +Cc: netdev, dsahern, haliu

On Thu, 12 Aug 2021 11:01:42 +0200
Andrea Claudi <aclaudi@redhat.com> wrote:

> On Wed, Aug 11, 2021 at 09:08:15AM -0700, Stephen Hemminger wrote:
> > It is bad style in C to do assignment in a conditional.
> > It causes errors, and is not anymore efficient.
> >   
> I agree with you.
> 
> There is a large number of similar assignments in other parts of the
> code; I can work on a treewide patch to address them all, if you think
> it's a good idea.
> 

I am looking into this, checkpatch seems to find them

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-12 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-07 16:58 [PATCH iproute2] lib: bpf_glue: remove useless assignment Andrea Claudi
2021-08-11  3:00 ` Stephen Hemminger
2021-08-11  9:12   ` Andrea Claudi
2021-08-11 16:08     ` Stephen Hemminger
2021-08-12  9:01       ` Andrea Claudi
2021-08-12 16:26         ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.