From: Linus Torvalds <torvalds@linux-foundation.org> To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Cc: Herbert Xu <herbert@gondor.apana.org.au>, Andrew Morton <akpm@linux-foundation.org>, Joerg Roedel <joerg.roedel@amd.com>, Guenter Roeck <linux@roeck-us.net>, Li Yang <leoyang.li@nxp.com>, Zhang Wei <zw@zh-kernel.org>, Dan Williams <dan.j.williams@intel.com>, Vinod Koul <vkoul@kernel.org>, linuxppc-dev <linuxppc-dev@lists.ozlabs.org>, dma <dmaengine@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org> Subject: Re: [PATCH] fsldma: fsl_ioread64*() do not need lower_32_bits() Date: Sat, 29 Aug 2020 10:29:55 -0700 [thread overview] Message-ID: <CAHk-=whH0ApHy0evN0q6AwQ+-a5RK56oMkYkkCJtTMnaq4FrNQ@mail.gmail.com> (raw) In-Reply-To: <20200829124538.7475-1-luc.vanoostenryck@gmail.com> [-- Attachment #1: Type: text/plain, Size: 2203 bytes --] On Sat, Aug 29, 2020 at 5:46 AM Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > > But the pointer is already 32-bit, so simply cast the pointer to u32. Yeah, that code was completely pointless. If the pointer had actually been 64-bit, the old code would have warned too. The odd thing is that the fsl_iowrite64() functions make sense. It's only the fsl_ioread64() functions that seem to be written by somebody who is really confused. That said, this patch only humors the confusion. The cast to 'u32' is completely pointless. In fact, it seems to be actively wrong, because it means that the later "fsl_addr + 1" is done entirely incorrectly - it now literally adds "1" to an integer value, while the iowrite() functions will add one to a "u32 __iomem *" pointer (so will do pointer arithmetic, and add 4). So this code has never ever worked correctly to begin with, but the patches to fix the warning miss the point. The problem isn't the warning, the problem is that the code is broken and completely wrong to begin with. And the "lower_32_bits()" thing has always been pure and utter confusion and complete garbage. I *think* the right patch is the one attached, but since this code is clearly utterly broken, I'd want somebody to test it. It has probably never ever worked on 32-bit powerpc, or did so purely by mistake (perhaps because nobody really cares - the only 64-bit use is this: static dma_addr_t get_cdar(struct fsldma_chan *chan) { return FSL_DMA_IN(chan, &chan->regs->cdar, 64) & ~FSL_DMA_SNEN; } and there are two users of that: one which ignores the return value, and one that looks like it might end up half-way working even if the value read was garbage (it's used only to compare against a "current descriptor" value). Anyway, the fix is definitely not to just shut up the warning. The warning is only a sign of utter confusion in that driver. Can somebody with the hardware test this on 32-bit ppc? And if not (judging by just how broken those functions are, maybe it never did work), can somebody with a ppc32 setup at least compile-test this patch and look at whether it makes sense, in ways the old code did not. Linus [-- Attachment #2: patch --] [-- Type: application/octet-stream, Size: 1167 bytes --] drivers/dma/fsldma.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/dma/fsldma.h b/drivers/dma/fsldma.h index 56f18ae99233..c574d223d52e 100644 --- a/drivers/dma/fsldma.h +++ b/drivers/dma/fsldma.h @@ -205,10 +205,10 @@ struct fsldma_chan { #else static u64 fsl_ioread64(const u64 __iomem *addr) { - u32 fsl_addr = lower_32_bits(addr); - u64 fsl_addr_hi = (u64)in_le32((u32 *)(fsl_addr + 1)) << 32; + u32 val_lo = in_le32((u32 __iomem *)addr); + u32 val_hi = in_le32((u32 __iomem *)addr + 1); - return fsl_addr_hi | in_le32((u32 *)fsl_addr); + return ((u64)val_hi << 32) + val_lo; } static void fsl_iowrite64(u64 val, u64 __iomem *addr) @@ -219,10 +219,10 @@ static void fsl_iowrite64(u64 val, u64 __iomem *addr) static u64 fsl_ioread64be(const u64 __iomem *addr) { - u32 fsl_addr = lower_32_bits(addr); - u64 fsl_addr_hi = (u64)in_be32((u32 *)fsl_addr) << 32; + u32 val_hi = in_be32((u32 __iomem *)addr); + u32 val_lo = in_be32((u32 __iomem *)addr+1); - return fsl_addr_hi | in_be32((u32 *)(fsl_addr + 1)); + return ((u64)val_hi << 32) + val_lo; } static void fsl_iowrite64be(u64 val, u64 __iomem *addr)
WARNING: multiple messages have this Message-ID (diff)
From: Linus Torvalds <torvalds@linux-foundation.org> To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Cc: Herbert Xu <herbert@gondor.apana.org.au>, Joerg Roedel <joerg.roedel@amd.com>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Li Yang <leoyang.li@nxp.com>, Zhang Wei <zw@zh-kernel.org>, Vinod Koul <vkoul@kernel.org>, dma <dmaengine@vger.kernel.org>, Andrew Morton <akpm@linux-foundation.org>, linuxppc-dev <linuxppc-dev@lists.ozlabs.org>, Dan Williams <dan.j.williams@intel.com>, Guenter Roeck <linux@roeck-us.net> Subject: Re: [PATCH] fsldma: fsl_ioread64*() do not need lower_32_bits() Date: Sat, 29 Aug 2020 10:29:55 -0700 [thread overview] Message-ID: <CAHk-=whH0ApHy0evN0q6AwQ+-a5RK56oMkYkkCJtTMnaq4FrNQ@mail.gmail.com> (raw) In-Reply-To: <20200829124538.7475-1-luc.vanoostenryck@gmail.com> [-- Attachment #1: Type: text/plain, Size: 2203 bytes --] On Sat, Aug 29, 2020 at 5:46 AM Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > > But the pointer is already 32-bit, so simply cast the pointer to u32. Yeah, that code was completely pointless. If the pointer had actually been 64-bit, the old code would have warned too. The odd thing is that the fsl_iowrite64() functions make sense. It's only the fsl_ioread64() functions that seem to be written by somebody who is really confused. That said, this patch only humors the confusion. The cast to 'u32' is completely pointless. In fact, it seems to be actively wrong, because it means that the later "fsl_addr + 1" is done entirely incorrectly - it now literally adds "1" to an integer value, while the iowrite() functions will add one to a "u32 __iomem *" pointer (so will do pointer arithmetic, and add 4). So this code has never ever worked correctly to begin with, but the patches to fix the warning miss the point. The problem isn't the warning, the problem is that the code is broken and completely wrong to begin with. And the "lower_32_bits()" thing has always been pure and utter confusion and complete garbage. I *think* the right patch is the one attached, but since this code is clearly utterly broken, I'd want somebody to test it. It has probably never ever worked on 32-bit powerpc, or did so purely by mistake (perhaps because nobody really cares - the only 64-bit use is this: static dma_addr_t get_cdar(struct fsldma_chan *chan) { return FSL_DMA_IN(chan, &chan->regs->cdar, 64) & ~FSL_DMA_SNEN; } and there are two users of that: one which ignores the return value, and one that looks like it might end up half-way working even if the value read was garbage (it's used only to compare against a "current descriptor" value). Anyway, the fix is definitely not to just shut up the warning. The warning is only a sign of utter confusion in that driver. Can somebody with the hardware test this on 32-bit ppc? And if not (judging by just how broken those functions are, maybe it never did work), can somebody with a ppc32 setup at least compile-test this patch and look at whether it makes sense, in ways the old code did not. Linus [-- Attachment #2: patch --] [-- Type: application/octet-stream, Size: 1167 bytes --] drivers/dma/fsldma.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/dma/fsldma.h b/drivers/dma/fsldma.h index 56f18ae99233..c574d223d52e 100644 --- a/drivers/dma/fsldma.h +++ b/drivers/dma/fsldma.h @@ -205,10 +205,10 @@ struct fsldma_chan { #else static u64 fsl_ioread64(const u64 __iomem *addr) { - u32 fsl_addr = lower_32_bits(addr); - u64 fsl_addr_hi = (u64)in_le32((u32 *)(fsl_addr + 1)) << 32; + u32 val_lo = in_le32((u32 __iomem *)addr); + u32 val_hi = in_le32((u32 __iomem *)addr + 1); - return fsl_addr_hi | in_le32((u32 *)fsl_addr); + return ((u64)val_hi << 32) + val_lo; } static void fsl_iowrite64(u64 val, u64 __iomem *addr) @@ -219,10 +219,10 @@ static void fsl_iowrite64(u64 val, u64 __iomem *addr) static u64 fsl_ioread64be(const u64 __iomem *addr) { - u32 fsl_addr = lower_32_bits(addr); - u64 fsl_addr_hi = (u64)in_be32((u32 *)fsl_addr) << 32; + u32 val_hi = in_be32((u32 __iomem *)addr); + u32 val_lo = in_be32((u32 __iomem *)addr+1); - return fsl_addr_hi | in_be32((u32 *)(fsl_addr + 1)); + return ((u64)val_hi << 32) + val_lo; } static void fsl_iowrite64be(u64 val, u64 __iomem *addr)
next prev parent reply other threads:[~2020-08-29 17:30 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-28 7:11 [PATCH] kernel.h: Silence sparse warning in lower_32_bits Herbert Xu 2020-08-29 10:51 ` Guenter Roeck 2020-08-29 12:45 ` [PATCH] dmaengine: fsldma: Do not pass pointers to lower_32_bits Herbert Xu 2020-08-29 15:08 ` Guenter Roeck 2020-08-29 12:45 ` [PATCH] fsldma: fsl_ioread64*() do not need lower_32_bits() Luc Van Oostenryck 2020-08-29 12:45 ` Luc Van Oostenryck 2020-08-29 17:29 ` Linus Torvalds [this message] 2020-08-29 17:29 ` Linus Torvalds 2020-08-29 20:40 ` Guenter Roeck 2020-08-29 20:40 ` Guenter Roeck 2020-08-29 21:20 ` Linus Torvalds 2020-08-29 21:20 ` Linus Torvalds 2020-08-31 1:54 ` Michael Ellerman 2020-08-31 1:54 ` Michael Ellerman 2020-08-31 6:39 ` Vinod Koul 2020-08-31 6:39 ` Vinod Koul 2020-08-31 14:25 ` Leo Li 2020-08-31 14:25 ` Leo Li 2020-08-30 12:11 ` Luc Van Oostenryck 2020-08-30 12:11 ` Luc Van Oostenryck 2020-08-29 15:05 Guenter Roeck 2020-08-29 15:05 ` Guenter Roeck 2020-08-29 15:58 ` Christophe Leroy 2020-08-29 15:58 ` Christophe Leroy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAHk-=whH0ApHy0evN0q6AwQ+-a5RK56oMkYkkCJtTMnaq4FrNQ@mail.gmail.com' \ --to=torvalds@linux-foundation.org \ --cc=akpm@linux-foundation.org \ --cc=dan.j.williams@intel.com \ --cc=dmaengine@vger.kernel.org \ --cc=herbert@gondor.apana.org.au \ --cc=joerg.roedel@amd.com \ --cc=leoyang.li@nxp.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@roeck-us.net \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=luc.vanoostenryck@gmail.com \ --cc=vkoul@kernel.org \ --cc=zw@zh-kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.