Re: [PATCH 2/6] fs/affs: Add printf format/argument verification andfix fallout

From: Geert Uytterhoeven
Date: Thu Nov 11 2010 - 04:20:42 EST


On Thu, Nov 11, 2010 at 00:46, Joe Perches <joe@xxxxxxxxxxx> wrote:
> Add __attribute__((format... to affs_error and affs_warning.

Thanks, nice catch!

> Change formats to match types of arguments.

You didn't fix any formats, you just added casts to silence the warnings?

> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
> @@ -355,7 +355,8 @@ affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_resul
>
> Â Â Â Â Â Â Â Â/* store new block */
> Â Â Â Â Â Â Â Âif (bh_result->b_blocknr)
> - Â Â Â Â Â Â Â Â Â Â Â affs_warning(sb, "get_block", "block already set (%x)", bh_result->b_blocknr);
> + Â Â Â Â Â Â Â Â Â Â Â affs_warning(sb, "get_block", "block already set (%lx)",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(unsigned long)bh_result->b_blocknr);

struct buffer_head.b_blocknr is sector_t, which can be either u64 or
unsigned long.
So casting it to unsigned long may truncate it.
Please cast to unsigned long long instead, and use %llx.

> Â Â Â Â Â Â Â ÂAFFS_BLOCK(sb, ext_bh, block) = cpu_to_be32(blocknr);
> Â Â Â Â Â Â Â ÂAFFS_HEAD(ext_bh)->block_count = cpu_to_be32(block + 1);
> Â Â Â Â Â Â Â Âaffs_adjust_checksum(ext_bh, blocknr - bh_result->b_blocknr + 1);
> @@ -377,7 +378,8 @@ affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_resul
> Â Â Â Âreturn 0;
>
> Âerr_big:
> - Â Â Â affs_error(inode->i_sb,"get_block","strange block request %d", block);
> + Â Â Â affs_error(inode->i_sb,"get_block","strange block request %d",
> + Â Â Â Â Â Â Â Â Â(int)block);

Same here, block is sector_t.

> Â Â Â Âreturn -EIO;
> Âerr_ext:
> Â Â Â Â// unlock cache
> @@ -848,8 +850,8 @@ affs_truncate(struct inode *inode)
> Â Â Â Â// lock cache
> Â Â Â Âext_bh = affs_get_extblock(inode, ext);
> Â Â Â Âif (IS_ERR(ext_bh)) {
> - Â Â Â Â Â Â Â affs_warning(sb, "truncate", "unexpected read error for ext block %u (%d)",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Âext, PTR_ERR(ext_bh));
> + Â Â Â Â Â Â Â affs_warning(sb, "truncate", "unexpected read error for ext block %u (%ld)",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â(unsigned int)ext, PTR_ERR(ext_bh));

Do you really need the cast here? ext is u32, which is unsigned int.

> Â Â Â Â Â Â Â Âreturn;
> Â Â Â Â}
> Â Â Â Âif (AFFS_I(inode)->i_lc) {
> @@ -895,8 +897,8 @@ affs_truncate(struct inode *inode)
> Â Â Â Â Â Â Â Â Â Â Â Âstruct buffer_head *bh = affs_bread_ino(inode, last_blk, 0);
> Â Â Â Â Â Â Â Â Â Â Â Âu32 tmp;
> Â Â Â Â Â Â Â Â Â Â Â Âif (IS_ERR(bh)) {
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â affs_warning(sb, "truncate", "unexpected read error for last block %u (%d)",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âext, PTR_ERR(bh));
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â affs_warning(sb, "truncate", "unexpected read error for last block %u (%ld)",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(unsigned int)ext, PTR_ERR(bh));

ext is u32.

> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âreturn;
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â Â Â Â Âtmp = be32_to_cpu(AFFS_DATA_HEAD(bh)->next);

Gr{oetje,eeting}s,

            Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
             Â Â -- Linus Torvalds
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i