Message ID | 1392930177.15264.5.camel@x220 (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, Feb 20, 2014 at 4:02 PM, Paul Bolle <pebolle@tiscali.nl> wrote: > Building radeon_ttm.o on 32 bit x86 triggers a warning: > In file included from include/asm-generic/bug.h:13:0, > from [...]/arch/x86/include/asm/bug.h:38, > from include/linux/bug.h:4, > from include/drm/drm_mm.h:39, > from include/drm/drm_vma_manager.h:26, > from include/drm/ttm/ttm_bo_api.h:35, > from drivers/gpu/drm/radeon/radeon_ttm.c:32: > drivers/gpu/drm/radeon/radeon_ttm.c: In function 'radeon_ttm_gtt_read': > include/linux/kernel.h:712:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] > (void) (&_min1 == &_min2); \ > ^ > drivers/gpu/drm/radeon/radeon_ttm.c:938:22: note: in expansion of macro 'min' > ssize_t cur_size = min(size, PAGE_SIZE - off); > ^ > > Silence this warning by casting "PAGE_SIZE - off" to size_t. Since > "PAGE_SIZE - off" is between 0 and PAGE_SIZE, and PAGE_SIZE is at most > 21 bits wide while size_t is at least 32 bits wide, this should be safe. > > Signed-off-by: Paul Bolle <pebolle@tiscali.nl> > --- > Compile tested only (on 32 and 64 bit x86). > > drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c > index 77f5b0c..5c87979 100644 > --- a/drivers/gpu/drm/radeon/radeon_ttm.c > +++ b/drivers/gpu/drm/radeon/radeon_ttm.c > @@ -935,7 +935,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, > while (size) { > loff_t p = *pos / PAGE_SIZE; > unsigned off = *pos & ~PAGE_MASK; > - ssize_t cur_size = min(size, PAGE_SIZE - off); > + ssize_t cur_size = min(size, (size_t)(PAGE_SIZE - off)); Isn't the usual way of dealing with these to do something like ssize_t cur_size = min_t(ssize_t, size, PAGE_SIZE - off) > struct page *page; > void *ptr; > > -- > 1.8.5.3 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/
On Thu, 2014-02-20 at 16:07 -0500, Ilia Mirkin wrote: > On Thu, Feb 20, 2014 at 4:02 PM, Paul Bolle <pebolle@tiscali.nl> wrote: > > @@ -935,7 +935,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, > > while (size) { > > loff_t p = *pos / PAGE_SIZE; > > unsigned off = *pos & ~PAGE_MASK; > > - ssize_t cur_size = min(size, PAGE_SIZE - off); > > + ssize_t cur_size = min(size, (size_t)(PAGE_SIZE - off)); > > Isn't the usual way of dealing with these to do something like > > ssize_t cur_size = min_t(ssize_t, size, PAGE_SIZE - off) I wouldn't know. I did $ git grep -n "(size_t)(PAGE_SIZE" arch/powerpc/mm/dma-noncoherent.c:357: size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); arch/tile/kernel/pci-dma.c:176: size_t bytes = min(size, (size_t)(PAGE_SIZE - offset)); arch/tile/kernel/pci-dma.c:192: size_t bytes = min(size, (size_t)(PAGE_SIZE - offset)); drivers/net/wireless/ti/wlcore/main.c:806: len = min(maxlen, (size_t)(PAGE_SIZE - wl->fwlog_size)); drivers/scsi/libfc/fc_libfc.c:143: (size_t)(PAGE_SIZE - (off & ~PAGE_MASK))); drivers/target/tcm_fc/tfc_io.c:160: tlen = min(tlen, (size_t)(PAGE_SIZE - drivers/target/tcm_fc/tfc_io.c:311: tlen = min(tlen, (size_t)(PAGE_SIZE - and concluded my solution was acceptable. Is your alternative considered to be better? Paul Bolle
On Thu, Feb 20, 2014 at 10:24:53PM +0100, Paul Bolle wrote: > On Thu, 2014-02-20 at 16:07 -0500, Ilia Mirkin wrote: > > On Thu, Feb 20, 2014 at 4:02 PM, Paul Bolle <pebolle@tiscali.nl> wrote: > > > @@ -935,7 +935,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, > > > while (size) { > > > loff_t p = *pos / PAGE_SIZE; > > > unsigned off = *pos & ~PAGE_MASK; > > > - ssize_t cur_size = min(size, PAGE_SIZE - off); > > > + ssize_t cur_size = min(size, (size_t)(PAGE_SIZE - off)); > > > > Isn't the usual way of dealing with these to do something like > > > > ssize_t cur_size = min_t(ssize_t, size, PAGE_SIZE - off) > > I wouldn't know. I did > $ git grep -n "(size_t)(PAGE_SIZE" > arch/powerpc/mm/dma-noncoherent.c:357: size_t seg_size = min((size_t)(PAGE_SIZE - offset), size); > arch/tile/kernel/pci-dma.c:176: size_t bytes = min(size, (size_t)(PAGE_SIZE - offset)); > arch/tile/kernel/pci-dma.c:192: size_t bytes = min(size, (size_t)(PAGE_SIZE - offset)); > drivers/net/wireless/ti/wlcore/main.c:806: len = min(maxlen, (size_t)(PAGE_SIZE - wl->fwlog_size)); > drivers/scsi/libfc/fc_libfc.c:143: (size_t)(PAGE_SIZE - (off & ~PAGE_MASK))); > drivers/target/tcm_fc/tfc_io.c:160: tlen = min(tlen, (size_t)(PAGE_SIZE - > drivers/target/tcm_fc/tfc_io.c:311: tlen = min(tlen, (size_t)(PAGE_SIZE - > > and concluded my solution was acceptable. Is your alternative considered > to be better? Yes, min_t() is specifically meant for this type of situation. On a side note, I think cur_size should be size_t rather than ssize_t. Thierry
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 77f5b0c..5c87979 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -935,7 +935,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf, while (size) { loff_t p = *pos / PAGE_SIZE; unsigned off = *pos & ~PAGE_MASK; - ssize_t cur_size = min(size, PAGE_SIZE - off); + ssize_t cur_size = min(size, (size_t)(PAGE_SIZE - off)); struct page *page; void *ptr;
Building radeon_ttm.o on 32 bit x86 triggers a warning: In file included from include/asm-generic/bug.h:13:0, from [...]/arch/x86/include/asm/bug.h:38, from include/linux/bug.h:4, from include/drm/drm_mm.h:39, from include/drm/drm_vma_manager.h:26, from include/drm/ttm/ttm_bo_api.h:35, from drivers/gpu/drm/radeon/radeon_ttm.c:32: drivers/gpu/drm/radeon/radeon_ttm.c: In function 'radeon_ttm_gtt_read': include/linux/kernel.h:712:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ drivers/gpu/drm/radeon/radeon_ttm.c:938:22: note: in expansion of macro 'min' ssize_t cur_size = min(size, PAGE_SIZE - off); ^ Silence this warning by casting "PAGE_SIZE - off" to size_t. Since "PAGE_SIZE - off" is between 0 and PAGE_SIZE, and PAGE_SIZE is at most 21 bits wide while size_t is at least 32 bits wide, this should be safe. Signed-off-by: Paul Bolle <pebolle@tiscali.nl> --- Compile tested only (on 32 and 64 bit x86). drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)