Skip to contentSkip to conversation

Staging: lustre: osc: Declare structure as static

PATCH In review Bhumika Goyal 2 participants 5 messages Feb 12, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Staging: lustre: osc: Declare structure as static

Declare structure as static since it is used only in this file. Problem found using sparse. Used grep to find occurences.

---
 drivers/staging/lustre/lustre/osc/osc_request.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
index 3ae00fc..beabb1c 100644
@@ -3256,7 +3256,7 @@ static int osc_process_config(struct obd_device *obd, u32 len, void *buf)
 	return osc_process_config_base(obd, buf);
 }
 
-struct obd_ops osc_obd_ops = {
+static struct obd_ops osc_obd_ops = {
 	.owner          = THIS_MODULE,
 	.setup          = osc_setup,
 	.precleanup     = osc_precleanup,
Signature · 1 line
1.9.1
#1 lore raw

I am sorry it was supposed to be [PATCH] and not [PATCH 1/2]. Will send it again.

#2 lore raw
In reply to Bhumika Goyal
Quoted 2 lines · Bhumika Goyal

Declare structure as static since it is used only in this file. Problem found using sparse. Used grep to find occurences.

Could it also be const? You can try annotating all declarations of this type as const and seeing if it compiles.

julia

Quoted 28 lines
---
 drivers/staging/lustre/lustre/osc/osc_request.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
index 3ae00fc..beabb1c 100644
@@ -3256,7 +3256,7 @@ static int osc_process_config(struct obd_device *obd, u32 len, void *buf)
 	return osc_process_config_base(obd, buf);
 }
 
-struct obd_ops osc_obd_ops = {
+static struct obd_ops osc_obd_ops = {
 	.owner          = THIS_MODULE,
 	.setup          = osc_setup,
 	.precleanup     = osc_precleanup,
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455255789-6050-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#3 lore raw
Quoted 9 lines · Julia Lawall
Quoted 2 lines · Bhumika Goyal

Declare structure as static since it is used only in this file. Problem found using sparse. Used grep to find occurences.

Could it also be const? You can try annotating all declarations of this type as const and seeing if it compiles.

I declared it as static const struct obd_ops osc_obd_ops but I am
getting warnings like :

drivers/staging/lustre/lustre/osc/osc_request.c:3312:6: warning: passing argument 1 of ‘class_register_type’ discards ‘const’ qualifier from pointer target type [enabled by default]

      LUSTRE_OSC_NAME, &osc_device_type);
      ^

In file included from drivers/staging/lustre/lustre/osc/osc_request.c:51:0:
drivers/staging/lustre/lustre/osc/../include/obd_class.h:75:5: note:
expected ‘struct obd_ops *’ but argument is of type ‘const struct obd_ops *’
int class_register_type(struct obd_ops *, struct md_ops *,

Quoted 39 lines

Possible reasons for the warnings?
julia

Review

Quoted 6 lines
Signed-off-by Bhumika Goyal <[email protected] <javascript:>>

---

 drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 
 1 file changed, 1 insertion(+), 1 deletion(-) 
(quoted diff) +0 -0

b/drivers/staging/lustre/lustre/osc/osc_request.c

drivers/staging/lustre/lustre/osc/osc_request.c static int osc_process_config(struct obd_device

Quoted 4 lines

index 3ae00fc..beabb1c 100644

drivers/staging/lustre/lustre/osc/osc_request.c +0 -0
@@ -3256,7 +3256,7 @@ static int osc_process_config(struct obd_device 

*obd, u32 len, void *buf)

Quoted 13 lines
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
         return osc_process_config_base(obd, buf); 
 } 
 
-struct obd_ops osc_obd_ops = { 
+static struct obd_ops osc_obd_ops = { 
         .owner          = THIS_MODULE, 
         .setup          = osc_setup, 
         .precleanup     = osc_precleanup, 
Signature · 4 lines
1.9.1 

-- 
You received this message because you are subscribed to the Google 

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected] <javascript:>.

Quoted 1 line

To post to this group, send email to [email protected]

<javascript:>.

Quoted 1 line

To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/1455255789-6050-1-git-send-email-bhumirks%40gmail.com.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#4 lore raw
Quoted 17 lines · Bhumika Goyal

On Friday, February 12, 2016 at 12:22:02 PM UTC+5:30, Julia Lawall wrote:
On Fri, 12 Feb 2016, Bhumika Goyal wrote:

> Declare structure as static since it is used only in this file.
> Problem found using sparse. Used grep to find occurences.

Could it also be const?  You can try annotating all declarations of this
type as const and seeing if it compiles.


   I declared it as static const struct obd_ops osc_obd_ops but I am getting warnings like :

Quoted 11 lines

drivers/staging/lustre/lustre/osc/osc_request.c:3312:6: warning: passing argument 1 of ‘class_register_type’ discards ‘const’ qualifier from pointer target type [enabled by default]
      LUSTRE_OSC_NAME, &osc_device_type);
      ^
In file included from drivers/staging/lustre/lustre/osc/osc_request.c:51:0:
drivers/staging/lustre/lustre/osc/../include/obd_class.h:75:5: note:
expected ‘struct obd_ops *’ but argument is of type ‘const struct obd_ops *’ int class_register_type(struct obd_ops *, struct md_ops *,

Possible reasons for the warnings?

If you mae something const, it has to be declared to be const at every place that it can be passed to. The compiler only checks that a const declaration is consistent within the scope of the declared variable. It won't check that the thing is not modified in a called function. So you have to change all occurrences of struct obd_ops inthe entire driver, not just the single structure that you are working on. It might not work out. But ih you make the changes, then the compiler will show you where the problem (ie an assignment to some field) is.

julia

Quoted 48 lines
      julia

      > Signed-off-by: Bhumika Goyal <[email protected]>
      > ---
      >  drivers/staging/lustre/lustre/osc/osc_request.c | 2 +-
      >  1 file changed, 1 insertion(+), 1 deletion(-)
      >
      > diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c
      b/drivers/staging/lustre/lustre/osc/osc_request.c
      > index 3ae00fc..beabb1c 100644
      > --- a/drivers/staging/lustre/lustre/osc/osc_request.c
      > +++ b/drivers/staging/lustre/lustre/osc/osc_request.c
      > @@ -3256,7 +3256,7 @@ static int osc_process_config(struct
      obd_device *obd, u32 len, void *buf)
      >          return osc_process_config_base(obd, buf);
      >  }
      >  
      > -struct obd_ops osc_obd_ops = {
      > +static struct obd_ops osc_obd_ops = {
      >          .owner          = THIS_MODULE,
      >          .setup          = osc_setup,
      >          .precleanup     = osc_precleanup,
      > --
      > 1.9.1
      >
      > --
      > You received this message because you are subscribed to the
      Google Groups "outreachy-kernel" group.
      > To unsubscribe from this group and stop receiving emails from
      it, send an email to [email protected].
      > To post to this group, send email to
      [email protected].
      > To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/1455255789-6050-1-git-se
      nd-email-bhumirks%40gmail.com.
      > For more options, visit https://groups.google.com/d/optout.
      >

--
You received this message because you are subscribed to the Google Groups
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/660d75f4-ceb0-4945-81e9- 8e4c2bb1cab0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.