From: Dan Carpenter <dan.carpenter@oracle.com>
To: Will Deacon <will@kernel.org>
Cc: Anan sun <anan.sun@mediatek.com>, Joerg Roedel <joro@8bytes.org>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Tomasz Figa <tfiga@chromium.org>,
Chao Hao <chao.hao@mediatek.com>,
iommu@lists.linux-foundation.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Matthias Brugger <matthias.bgg@gmail.com>,
Colin King <colin.king@canonical.com>,
Yong Wu <yong.wu@mediatek.com>
Subject: Re: [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero
Date: Tue, 09 Feb 2021 09:19:23 +0000 [thread overview]
Message-ID: <20210209091923.GO2696@kadam> (raw)
In-Reply-To: <20210204092558.GA20244@willie-the-truck>
On Thu, Feb 04, 2021 at 09:25:58AM +0000, Will Deacon wrote:
> On Wed, Feb 03, 2021 at 01:59:36PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the check for domid < 0 is always false because domid
> > is unsigned. Fix this by making it signed.
> >
> > Addresses-CoverityL ("Unsigned comparison against 0")
>
> Typo here ('L' instead of ':')
>
> > Fixes: ab1d5281a62b ("iommu/mediatek: Add iova reserved function")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > drivers/iommu/mtk_iommu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 0ad14a7604b1..823d719945b2 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -640,7 +640,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
> > struct list_head *head)
> > {
> > struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
> > - unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
> > + int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
>
> Not sure if it's intentional, but this also makes 'i' signed. It probably
> should remain 'unsigned' to match 'iova_region_nr' in
> 'struct mtk_iommu_plat_data'.
iova_region_nr is either 1 or 5 so unsigned doesn't matter.
I once almost introduced a bug where the iterator was supposed to be
size_t. I fixed a bug by making it signed but I ended up introducing a
new bug. But generally that's pretty rare. The more common case is
that making iterators unsigned introduces bugs.
It's better to default to "int i;" and if more complicated types are
required that should stand out. "size_t pg_idx;" or whatever.
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Will Deacon <will@kernel.org>
Cc: Anan sun <anan.sun@mediatek.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Chao Hao <chao.hao@mediatek.com>,
iommu@lists.linux-foundation.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Matthias Brugger <matthias.bgg@gmail.com>,
Colin King <colin.king@canonical.com>
Subject: Re: [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero
Date: Tue, 9 Feb 2021 12:19:23 +0300 [thread overview]
Message-ID: <20210209091923.GO2696@kadam> (raw)
In-Reply-To: <20210204092558.GA20244@willie-the-truck>
On Thu, Feb 04, 2021 at 09:25:58AM +0000, Will Deacon wrote:
> On Wed, Feb 03, 2021 at 01:59:36PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the check for domid < 0 is always false because domid
> > is unsigned. Fix this by making it signed.
> >
> > Addresses-CoverityL ("Unsigned comparison against 0")
>
> Typo here ('L' instead of ':')
>
> > Fixes: ab1d5281a62b ("iommu/mediatek: Add iova reserved function")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > drivers/iommu/mtk_iommu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 0ad14a7604b1..823d719945b2 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -640,7 +640,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
> > struct list_head *head)
> > {
> > struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
> > - unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
> > + int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
>
> Not sure if it's intentional, but this also makes 'i' signed. It probably
> should remain 'unsigned' to match 'iova_region_nr' in
> 'struct mtk_iommu_plat_data'.
iova_region_nr is either 1 or 5 so unsigned doesn't matter.
I once almost introduced a bug where the iterator was supposed to be
size_t. I fixed a bug by making it signed but I ended up introducing a
new bug. But generally that's pretty rare. The more common case is
that making iterators unsigned introduces bugs.
It's better to default to "int i;" and if more complicated types are
required that should stand out. "size_t pg_idx;" or whatever.
regards,
dan carpenter
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Will Deacon <will@kernel.org>
Cc: Anan sun <anan.sun@mediatek.com>, Joerg Roedel <joro@8bytes.org>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Tomasz Figa <tfiga@chromium.org>,
Chao Hao <chao.hao@mediatek.com>,
iommu@lists.linux-foundation.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Matthias Brugger <matthias.bgg@gmail.com>,
Colin King <colin.king@canonical.com>,
Yong Wu <yong.wu@mediatek.com>
Subject: Re: [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero
Date: Tue, 9 Feb 2021 12:19:23 +0300 [thread overview]
Message-ID: <20210209091923.GO2696@kadam> (raw)
In-Reply-To: <20210204092558.GA20244@willie-the-truck>
On Thu, Feb 04, 2021 at 09:25:58AM +0000, Will Deacon wrote:
> On Wed, Feb 03, 2021 at 01:59:36PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the check for domid < 0 is always false because domid
> > is unsigned. Fix this by making it signed.
> >
> > Addresses-CoverityL ("Unsigned comparison against 0")
>
> Typo here ('L' instead of ':')
>
> > Fixes: ab1d5281a62b ("iommu/mediatek: Add iova reserved function")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > drivers/iommu/mtk_iommu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 0ad14a7604b1..823d719945b2 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -640,7 +640,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
> > struct list_head *head)
> > {
> > struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
> > - unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
> > + int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
>
> Not sure if it's intentional, but this also makes 'i' signed. It probably
> should remain 'unsigned' to match 'iova_region_nr' in
> 'struct mtk_iommu_plat_data'.
iova_region_nr is either 1 or 5 so unsigned doesn't matter.
I once almost introduced a bug where the iterator was supposed to be
size_t. I fixed a bug by making it signed but I ended up introducing a
new bug. But generally that's pretty rare. The more common case is
that making iterators unsigned introduces bugs.
It's better to default to "int i;" and if more complicated types are
required that should stand out. "size_t pg_idx;" or whatever.
regards,
dan carpenter
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Will Deacon <will@kernel.org>
Cc: Anan sun <anan.sun@mediatek.com>, Joerg Roedel <joro@8bytes.org>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
Tomasz Figa <tfiga@chromium.org>,
Chao Hao <chao.hao@mediatek.com>,
iommu@lists.linux-foundation.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Matthias Brugger <matthias.bgg@gmail.com>,
Colin King <colin.king@canonical.com>,
Yong Wu <yong.wu@mediatek.com>
Subject: Re: [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero
Date: Tue, 9 Feb 2021 12:19:23 +0300 [thread overview]
Message-ID: <20210209091923.GO2696@kadam> (raw)
In-Reply-To: <20210204092558.GA20244@willie-the-truck>
On Thu, Feb 04, 2021 at 09:25:58AM +0000, Will Deacon wrote:
> On Wed, Feb 03, 2021 at 01:59:36PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the check for domid < 0 is always false because domid
> > is unsigned. Fix this by making it signed.
> >
> > Addresses-CoverityL ("Unsigned comparison against 0")
>
> Typo here ('L' instead of ':')
>
> > Fixes: ab1d5281a62b ("iommu/mediatek: Add iova reserved function")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > drivers/iommu/mtk_iommu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 0ad14a7604b1..823d719945b2 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -640,7 +640,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
> > struct list_head *head)
> > {
> > struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
> > - unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
> > + int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
>
> Not sure if it's intentional, but this also makes 'i' signed. It probably
> should remain 'unsigned' to match 'iova_region_nr' in
> 'struct mtk_iommu_plat_data'.
iova_region_nr is either 1 or 5 so unsigned doesn't matter.
I once almost introduced a bug where the iterator was supposed to be
size_t. I fixed a bug by making it signed but I ended up introducing a
new bug. But generally that's pretty rare. The more common case is
that making iterators unsigned introduces bugs.
It's better to default to "int i;" and if more complicated types are
required that should stand out. "size_t pg_idx;" or whatever.
regards,
dan carpenter
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Will Deacon <will@kernel.org>
Cc: Colin King <colin.king@canonical.com>,
Joerg Roedel <joro@8bytes.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
Anan sun <anan.sun@mediatek.com>, Yong Wu <yong.wu@mediatek.com>,
Chao Hao <chao.hao@mediatek.com>,
Tomasz Figa <tfiga@chromium.org>,
iommu@lists.linux-foundation.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero
Date: Tue, 9 Feb 2021 12:19:23 +0300 [thread overview]
Message-ID: <20210209091923.GO2696@kadam> (raw)
In-Reply-To: <20210204092558.GA20244@willie-the-truck>
On Thu, Feb 04, 2021 at 09:25:58AM +0000, Will Deacon wrote:
> On Wed, Feb 03, 2021 at 01:59:36PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the check for domid < 0 is always false because domid
> > is unsigned. Fix this by making it signed.
> >
> > Addresses-CoverityL ("Unsigned comparison against 0")
>
> Typo here ('L' instead of ':')
>
> > Fixes: ab1d5281a62b ("iommu/mediatek: Add iova reserved function")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > drivers/iommu/mtk_iommu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> > index 0ad14a7604b1..823d719945b2 100644
> > --- a/drivers/iommu/mtk_iommu.c
> > +++ b/drivers/iommu/mtk_iommu.c
> > @@ -640,7 +640,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
> > struct list_head *head)
> > {
> > struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
> > - unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
> > + int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
>
> Not sure if it's intentional, but this also makes 'i' signed. It probably
> should remain 'unsigned' to match 'iova_region_nr' in
> 'struct mtk_iommu_plat_data'.
iova_region_nr is either 1 or 5 so unsigned doesn't matter.
I once almost introduced a bug where the iterator was supposed to be
size_t. I fixed a bug by making it signed but I ended up introducing a
new bug. But generally that's pretty rare. The more common case is
that making iterators unsigned introduces bugs.
It's better to default to "int i;" and if more complicated types are
required that should stand out. "size_t pg_idx;" or whatever.
regards,
dan carpenter
next prev parent reply other threads:[~2021-02-09 9:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 13:59 [PATCH][next] iommu/mediatek: Fix unsigned domid comparison with less than zero Colin King
2021-02-03 13:59 ` Colin King
2021-02-03 13:59 ` Colin King
2021-02-03 13:59 ` Colin King
2021-02-03 13:59 ` Colin King
2021-02-04 1:11 ` Yong Wu
2021-02-04 1:11 ` Yong Wu
2021-02-04 1:11 ` Yong Wu
2021-02-04 1:11 ` Yong Wu
2021-02-04 1:11 ` Yong Wu
2021-02-04 9:25 ` Will Deacon
2021-02-04 9:25 ` Will Deacon
2021-02-04 9:25 ` Will Deacon
2021-02-04 9:25 ` Will Deacon
2021-02-04 9:25 ` Will Deacon
2021-02-04 13:31 ` Joerg Roedel
2021-02-04 13:31 ` Joerg Roedel
2021-02-04 13:31 ` Joerg Roedel
2021-02-04 13:31 ` Joerg Roedel
2021-02-04 13:31 ` Joerg Roedel
2021-02-09 9:19 ` Dan Carpenter [this message]
2021-02-09 9:19 ` Dan Carpenter
2021-02-09 9:19 ` Dan Carpenter
2021-02-09 9:19 ` Dan Carpenter
2021-02-09 9:19 ` Dan Carpenter
2021-02-09 10:57 ` AW: " Walter Harms
2021-02-09 10:57 ` Walter Harms
2021-02-09 10:57 ` Walter Harms
2021-02-09 10:57 ` Walter Harms
2021-02-09 10:57 ` Walter Harms
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=20210209091923.GO2696@kadam \
--to=dan.carpenter@oracle.com \
--cc=anan.sun@mediatek.com \
--cc=chao.hao@mediatek.com \
--cc=colin.king@canonical.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=tfiga@chromium.org \
--cc=will@kernel.org \
--cc=yong.wu@mediatek.com \
/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: link
Be 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.