Skip to contentSkip to conversation

blk-throttle: Suppress a compiler warning

PATCH In review Bart Van Assche 2 participants 4 messages Apr 19, 2017 – Apr 20, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-throttle: Suppress a compiler warning

Avoid that the following warning is reported when building with W=1 and with CONFIG_BLK_DEV_THROTTLING_LOW=n:

block/blk-throttle.c: In function ‘blk_throtl_bio’:
block/blk-throttle.c:2042:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]

  int ret;
      ^~~
---
 block/blk-throttle.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-throttle.c +4 -0
index c82bf9b1fe72..9081ed9a5345 100644
@@ -2059,6 +2059,10 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	if (ret == 0 || ret == -EBUSY)
 		bio->bi_cg_private = tg;
 	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	/* Avoid that the compiler complains about not using ret */
+	if (ret) {
+	}
 #endif
 	blk_throtl_update_idletime(tg);
 
Signature · 1 line
2.12.2
maintainer
#1 lore raw
Quoted 19 lines · Bart Van Assche

Avoid that the following warning is reported when building with W=1 and with CONFIG_BLK_DEV_THROTTLING_LOW=n:

block/blk-throttle.c: In function ‘blk_throtl_bio’:
block/blk-throttle.c:2042:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]

  int ret;
      ^~~
---
 block/blk-throttle.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-throttle.c +0 -0
index c82bf9b1fe72..9081ed9a5345 100644

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, · line 2066

Quoted 8 lines
block/blk-throttle.c +4 -0
@@ -2059,6 +2059,10 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	if (ret == 0 || ret == -EBUSY)
 		bio->bi_cg_private = tg;
 	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	/* Avoid that the compiler complains about not using ret */
+	if (ret) {
+	}
 #endif

Ugh, that may get rid of the warning, but it does not help on the readability or the ifdefs. How about something like the below? Naming could probably be improved...

block/blk-throttle.c +15 -7
index c82bf9b1fe72..b78db2e5fdff 100644
@@ -2030,6 +2030,20 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td)
 }
 #endif
 
+static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio)
+{
+#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
+	int ret;
+
+	ret = bio_associate_current(bio);
+	if (ret == 0 || ret == -EBUSY)
+		bio->bi_cg_private = tg;
+	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	bio_associate_current(bio);
+#endif
+}
+
 bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 		    struct bio *bio)
 {
@@ -2039,7 +2053,6 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	bool rw = bio_data_dir(bio);
 	bool throttled = false;
 	struct throtl_data *td = tg->td;
-	int ret;
 
 	WARN_ON_ONCE(!rcu_read_lock_held());
 
@@ -2054,12 +2067,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	if (unlikely(blk_queue_bypass(q)))
 		goto out_unlock;
 
-	ret = bio_associate_current(bio);
-#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
-	if (ret == 0 || ret == -EBUSY)
-		bio->bi_cg_private = tg;
-	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
-#endif
+	blk_throtl_assoc_bio(tg, bio);
 	blk_throtl_update_idletime(tg);
 
 	sq = &tg->service_queue;
Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 6 lines · Jens Axboe
Quoted 5 lines · Bart Van Assche

Avoid that the following warning is reported when building with W=3D1 and with CONFIG_BLK_DEV_THROTTLING_LOW=3Dn:
=20
block/blk-throttle.c: In function =91blk_throtl_bio=92:
block/blk-throttle.c:2042:6: warning: variable =91ret=92 set but not us=

ed [-Wunused-but-set-variable]

Quoted 6 lines
Quoted 6 lines
  int ret;
      ^~~

=20

---

Quoted 8 lines

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, str=

Quoted 8 lines
 block/blk-throttle.c | 4 ++++
 1 file changed, 4 insertions(+)

=20

block/blk-throttle.c +0 -0
index c82bf9b1fe72..9081ed9a5345 100644
@@ -2059,6 +2059,10 @@ bool blk_throtl_bio(struct request_queue *q, str=

uct blkcg_gq *blkg,

block/blk-throttle.c static inline void throtl_update_latency_buckets(s=

Quoted 19 lines

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, str= · line 2066

Quoted 8 lines
block/blk-throttle.c +4 -0
 	if (ret =3D=3D 0 || ret =3D=3D -EBUSY)
 		bio->bi_cg_private =3D tg;
 	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	/* Avoid that the compiler complains about not using ret */
+	if (ret) {
+	}
 #endif

=20
Ugh, that may get rid of the warning, but it does not help on the readability or the ifdefs. How about something like the below? Naming could probably be improved...
=20
=20

block/blk-throttle.c +0 -0
index c82bf9b1fe72..b78db2e5fdff 100644
@@ -2030,6 +2030,20 @@ static inline void throtl_update_latency_buckets(s=

truct throtl_data *td)

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, struct=

Quoted 21 lines
block/blk-throttle.c +0 -0
 }
 #endif

=20

block/blk-throttle.c +14 -0
+static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio)
+{
+#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
+	int ret;
+
+	ret =3D bio_associate_current(bio);
+	if (ret =3D=3D 0 || ret =3D=3D -EBUSY)
+		bio->bi_cg_private =3D tg;
+	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	bio_associate_current(bio);
+#endif
+}
+
 bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 		    struct bio *bio)
 {
@@ -2039,7 +2053,6 @@ bool blk_throtl_bio(struct request_queue *q, struct=

blkcg_gq *blkg,

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, struc=

Quoted 8 lines
block/blk-throttle.c +0 -1
 	bool rw =3D bio_data_dir(bio);
 	bool throttled =3D false;
 	struct throtl_data *td =3D tg->td;
-	int ret;

=20
WARN_ON_ONCE(!rcu_read_lock_held());
=20

block/blk-throttle.c +0 -0
@@ -2054,12 +2067,7 @@ bool blk_throtl_bio(struct request_queue *q, struc=

t blkcg_gq *blkg,

Quoted 11 lines
block/blk-throttle.c +0 -0
 	if (unlikely(blk_queue_bypass(q)))
 		goto out_unlock;

=20

block/blk-throttle.c +1 -6
-	ret =3D bio_associate_current(bio);
-#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
-	if (ret =3D=3D 0 || ret =3D=3D -EBUSY)
-		bio->bi_cg_private =3D tg;
-	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
-#endif
+	blk_throtl_assoc_bio(tg, bio);
 	blk_throtl_update_idletime(tg);
Quoted 3 lines

=20
sq =3D &tg->service_queue;
=20

Hello Jens,

The above patch looks fine to me. Do you want to queue this patch with my Reviewed-by or do you prefer that I post the above as a v2?

Thanks,

Bart.=

maintainer
#3 lore raw
Quoted 81 lines · Bart Van Assche
Quoted 80 lines · Jens Axboe
Quoted 19 lines · Bart Van Assche

Avoid that the following warning is reported when building with W=1 and with CONFIG_BLK_DEV_THROTTLING_LOW=n:

block/blk-throttle.c: In function ‘blk_throtl_bio’:
block/blk-throttle.c:2042:6: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]

  int ret;
      ^~~
---
 block/blk-throttle.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-throttle.c +0 -0
index c82bf9b1fe72..9081ed9a5345 100644

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, · line 2066

Quoted 8 lines
block/blk-throttle.c +4 -0
@@ -2059,6 +2059,10 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	if (ret == 0 || ret == -EBUSY)
 		bio->bi_cg_private = tg;
 	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	/* Avoid that the compiler complains about not using ret */
+	if (ret) {
+	}
 #endif

Ugh, that may get rid of the warning, but it does not help on the readability or the ifdefs. How about something like the below? Naming could probably be improved...

block/blk-throttle.c +15 -7
index c82bf9b1fe72..b78db2e5fdff 100644
@@ -2030,6 +2030,20 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td)
 }
 #endif
 
+static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio)
+{
+#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
+	int ret;
+
+	ret = bio_associate_current(bio);
+	if (ret == 0 || ret == -EBUSY)
+		bio->bi_cg_private = tg;
+	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
+#else
+	bio_associate_current(bio);
+#endif
+}
+
 bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 		    struct bio *bio)
 {
@@ -2039,7 +2053,6 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	bool rw = bio_data_dir(bio);
 	bool throttled = false;
 	struct throtl_data *td = tg->td;
-	int ret;
 
 	WARN_ON_ONCE(!rcu_read_lock_held());
 
@@ -2054,12 +2067,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
 	if (unlikely(blk_queue_bypass(q)))
 		goto out_unlock;
 
-	ret = bio_associate_current(bio);
-#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
-	if (ret == 0 || ret == -EBUSY)
-		bio->bi_cg_private = tg;
-	blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
-#endif
+	blk_throtl_assoc_bio(tg, bio);
 	blk_throtl_update_idletime(tg);
 
Quoted 7 lines

block/blk-throttle.c bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, · line 2073

Quoted 2 lines
block/blk-throttle.c +0 -0
 	sq = &tg->service_queue;

Hello Jens,

The above patch looks fine to me. Do you want to queue this patch with my Reviewed-by or do you prefer that I post the above as a v2?

Thanks for checking, I'll just add it with your reviewed/reported-by tags.

Signature · 1 line
Jens Axboe