* [bug report] drm/xen-front: Add support for Xen PV display frontend
@ 2020-04-21 10:45 Dan Carpenter
2020-04-21 11:34 ` Oleksandr Andrushchenko
2020-04-21 15:29 ` Julia Lawall
0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2020-04-21 10:45 UTC (permalink / raw)
To: oleksandr_andrushchenko; +Cc: xen-devel, kernel-janitors, dri-devel
Hi Kernel Janitors,
Here is another idea that someone could work on, fixing the
IS_ERR_OR_NULL() checks in the xen driver.
The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
display frontend" from Apr 3, 2018, leads to the following static
checker warning:
drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
warn: passing zero to 'ERR_CAST'
drivers/gpu/drm/xen/xen_drm_front_gem.c
133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
134 size_t size)
135 {
136 struct xen_gem_object *xen_obj;
137
138 xen_obj = gem_create(dev, size);
139 if (IS_ERR_OR_NULL(xen_obj))
140 return ERR_CAST(xen_obj);
This warning is old and it's actually the result of a bug I had in my
devel version of Smatch yesterday. xen_obj can't really be NULL, but
if it were then the caller would return success which would probably
create some issues.
When a function returns both error pointers and NULL then NULL is a
special case of success. Like say you have: "p = start_feature();".
If there is an allocation failure, then the code should return -ENOMEM
and the whole thing should fail. But if the feature is optional and
the user has disabled it in the config then we return NULL and the
caller has to be able to accept that. There are a lot of these
IS_ERR_OR_NULL() checks in the xen driver...
The one here is clearly buggy because returning NULL would lead to a
run time failure. All these IS_ERR_OR_NULL() should be checked and
probably changed to just IS_ERR().
This sort of change is probably change is probably easiest if you build
the Smatch DB and you can check if Smatch thinks the functions return
NULL.
~/smatch/smatch_data/db/smdb.py return_states gem_create | grep INTERNAL
drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 58 | (-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 62 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 66 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 68 | 0,(-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
Smatch thinks that gem_create() sometimes returns NULL or error pointers
but that's because of a bug in the unreleased version of Smatch and
because gem_create() uses IS_ERR_OR_NULL().
141
142 return &xen_obj->base;
143 }
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 10:45 [bug report] drm/xen-front: Add support for Xen PV display frontend Dan Carpenter
@ 2020-04-21 11:34 ` Oleksandr Andrushchenko
2020-04-21 11:51 ` Dan Carpenter
2020-04-21 15:29 ` Julia Lawall
1 sibling, 1 reply; 9+ messages in thread
From: Oleksandr Andrushchenko @ 2020-04-21 11:34 UTC (permalink / raw)
To: Dan Carpenter
Cc: xen-devel@lists.xenproject.org, kernel-janitors@vger.kernel.org,
dri-devel@lists.freedesktop.org
On 4/21/20 13:45, Dan Carpenter wrote:
> Hi Kernel Janitors,
Hi
>
> Here is another idea that someone could work on, fixing the
> IS_ERR_OR_NULL() checks in the xen driver.
>
> The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
> display frontend" from Apr 3, 2018, leads to the following static
> checker warning:
>
> drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
> warn: passing zero to 'ERR_CAST'
>
> drivers/gpu/drm/xen/xen_drm_front_gem.c
> 133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
> 134 size_t size)
> 135 {
> 136 struct xen_gem_object *xen_obj;
> 137
> 138 xen_obj = gem_create(dev, size);
> 139 if (IS_ERR_OR_NULL(xen_obj))
> 140 return ERR_CAST(xen_obj);
>
> This warning is old and it's actually the result of a bug I had in my
> devel version of Smatch yesterday. xen_obj can't really be NULL, but
> if it were then the caller would return success which would probably
> create some issues.
>
> When a function returns both error pointers and NULL then NULL is a
> special case of success. Like say you have: "p = start_feature();".
> If there is an allocation failure, then the code should return -ENOMEM
> and the whole thing should fail. But if the feature is optional and
> the user has disabled it in the config then we return NULL and the
> caller has to be able to accept that. There are a lot of these
> IS_ERR_OR_NULL() checks in the xen driver...
>
> The one here is clearly buggy because returning NULL would lead to a
> run time failure. All these IS_ERR_OR_NULL() should be checked and
> probably changed to just IS_ERR().
>
> This sort of change is probably change is probably easiest if you build
> the Smatch DB and you can check if Smatch thinks the functions return
> NULL.
>
> ~/smatch/smatch_data/db/smdb.py return_states gem_create | grep INTERNAL
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 58 | (-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 62 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 66 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 68 | 0,(-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
>
> Smatch thinks that gem_create() sometimes returns NULL or error pointers
> but that's because of a bug in the unreleased version of Smatch and
> because gem_create() uses IS_ERR_OR_NULL().
>
> 141
> 142 return &xen_obj->base;
> 143 }
>
> regards,
> dan carpenter
Thank you for the report, I will try to find some time to look into this
and come up with fixes.
Could you please (probably off-list) instruct me or give any pointers to
how to reproduce
the results of the analyzer shown above?
Thank you,
Oleksandr
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 11:34 ` Oleksandr Andrushchenko
@ 2020-04-21 11:51 ` Dan Carpenter
2020-04-21 12:54 ` Oleksandr Andrushchenko
2020-05-08 7:34 ` Oleksandr Andrushchenko
0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2020-04-21 11:51 UTC (permalink / raw)
To: Oleksandr Andrushchenko
Cc: xen-devel@lists.xenproject.org, kernel-janitors@vger.kernel.org,
dri-devel@lists.freedesktop.org
It turns out there aren't that many of these in xen.
$ grep IS_ERR_OR_NULL drivers/gpu/drm/xen/ -Rn
drivers/gpu/drm/xen/xen_drm_front_kms.c:63: if (IS_ERR_OR_NULL(fb))
drivers/gpu/drm/xen/xen_drm_front_gem.c:86: if (IS_ERR_OR_NULL(xen_obj))
drivers/gpu/drm/xen/xen_drm_front_gem.c:120: if (IS_ERR_OR_NULL(xen_obj->pages)) {
drivers/gpu/drm/xen/xen_drm_front_gem.c:139: if (IS_ERR_OR_NULL(xen_obj))
drivers/gpu/drm/xen/xen_drm_front_gem.c:197: if (IS_ERR_OR_NULL(xen_obj))
drivers/gpu/drm/xen/xen_drm_front.c:403: if (IS_ERR_OR_NULL(obj)) {
They're all wrong, because if the pointer was really NULL then it's
not handled correctly and would eventually lead to a runtime failure.
Normally Smatch is smart enough to know that the pointer isn't NULL so
it doesn't generate a warning but yesterday I introduced a bug in Smatch
by mistake. It's fixed now.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 11:51 ` Dan Carpenter
@ 2020-04-21 12:54 ` Oleksandr Andrushchenko
2020-05-08 7:34 ` Oleksandr Andrushchenko
1 sibling, 0 replies; 9+ messages in thread
From: Oleksandr Andrushchenko @ 2020-04-21 12:54 UTC (permalink / raw)
To: Dan Carpenter
Cc: xen-devel@lists.xenproject.org, kernel-janitors@vger.kernel.org,
dri-devel@lists.freedesktop.org
On 4/21/20 14:51, Dan Carpenter wrote:
> It turns out there aren't that many of these in xen.
>
> $ grep IS_ERR_OR_NULL drivers/gpu/drm/xen/ -Rn
> drivers/gpu/drm/xen/xen_drm_front_kms.c:63: if (IS_ERR_OR_NULL(fb))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:86: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:120: if (IS_ERR_OR_NULL(xen_obj->pages)) {
> drivers/gpu/drm/xen/xen_drm_front_gem.c:139: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:197: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front.c:403: if (IS_ERR_OR_NULL(obj)) {
>
> They're all wrong, because if the pointer was really NULL then it's
> not handled correctly and would eventually lead to a runtime failure.
>
> Normally Smatch is smart enough to know that the pointer isn't NULL so
> it doesn't generate a warning but yesterday I introduced a bug in Smatch
> by mistake. It's fixed now.
>
> regards,
> dan carpenter
>
Thank you,
I'll have a look at those
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 11:51 ` Dan Carpenter
2020-04-21 12:54 ` Oleksandr Andrushchenko
@ 2020-05-08 7:34 ` Oleksandr Andrushchenko
1 sibling, 0 replies; 9+ messages in thread
From: Oleksandr Andrushchenko @ 2020-05-08 7:34 UTC (permalink / raw)
To: Dan Carpenter
Cc: xen-devel@lists.xenproject.org, kernel-janitors@vger.kernel.org,
dri-devel@lists.freedesktop.org
On 4/21/20 2:51 PM, Dan Carpenter wrote:
> It turns out there aren't that many of these in xen.
>
> $ grep IS_ERR_OR_NULL drivers/gpu/drm/xen/ -Rn
> drivers/gpu/drm/xen/xen_drm_front_kms.c:63: if (IS_ERR_OR_NULL(fb))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:86: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:120: if (IS_ERR_OR_NULL(xen_obj->pages)) {
> drivers/gpu/drm/xen/xen_drm_front_gem.c:139: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front_gem.c:197: if (IS_ERR_OR_NULL(xen_obj))
> drivers/gpu/drm/xen/xen_drm_front.c:403: if (IS_ERR_OR_NULL(obj)) {
>
> They're all wrong, because if the pointer was really NULL then it's
> not handled correctly and would eventually lead to a runtime failure.
It seems that you were right and I can simply change all IS_ERR_OR_NULL
to just IS_ERR
I am planning a series of patches later on, so I'll include this fix as well
>
> Normally Smatch is smart enough to know that the pointer isn't NULL so
> it doesn't generate a warning but yesterday I introduced a bug in Smatch
> by mistake. It's fixed now.
>
> regards,
> dan carpenter
>
Thank you,
Oleksandr
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 10:45 [bug report] drm/xen-front: Add support for Xen PV display frontend Dan Carpenter
2020-04-21 11:34 ` Oleksandr Andrushchenko
@ 2020-04-21 15:29 ` Julia Lawall
2020-04-21 17:52 ` Dan Carpenter
1 sibling, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2020-04-21 15:29 UTC (permalink / raw)
To: Dan Carpenter
Cc: xen-devel, kernel-janitors, dri-devel, oleksandr_andrushchenko
On Tue, 21 Apr 2020, Dan Carpenter wrote:
> Hi Kernel Janitors,
>
> Here is another idea that someone could work on, fixing the
> IS_ERR_OR_NULL() checks in the xen driver.
>
> The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
> display frontend" from Apr 3, 2018, leads to the following static
> checker warning:
>
> drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
> warn: passing zero to 'ERR_CAST'
>
> drivers/gpu/drm/xen/xen_drm_front_gem.c
> 133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
> 134 size_t size)
> 135 {
> 136 struct xen_gem_object *xen_obj;
> 137
> 138 xen_obj = gem_create(dev, size);
> 139 if (IS_ERR_OR_NULL(xen_obj))
> 140 return ERR_CAST(xen_obj);
Are the other occurrences of this also a possible problem? There are a
few others outside of xen.
julia
>
> This warning is old and it's actually the result of a bug I had in my
> devel version of Smatch yesterday. xen_obj can't really be NULL, but
> if it were then the caller would return success which would probably
> create some issues.
>
> When a function returns both error pointers and NULL then NULL is a
> special case of success. Like say you have: "p = start_feature();".
> If there is an allocation failure, then the code should return -ENOMEM
> and the whole thing should fail. But if the feature is optional and
> the user has disabled it in the config then we return NULL and the
> caller has to be able to accept that. There are a lot of these
> IS_ERR_OR_NULL() checks in the xen driver...
>
> The one here is clearly buggy because returning NULL would lead to a
> run time failure. All these IS_ERR_OR_NULL() should be checked and
> probably changed to just IS_ERR().
>
> This sort of change is probably change is probably easiest if you build
> the Smatch DB and you can check if Smatch thinks the functions return
> NULL.
>
> ~/smatch/smatch_data/db/smdb.py return_states gem_create | grep INTERNAL
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 58 | (-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 62 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 66 | 4065035897849303040 | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
> drivers/gpu/drm/xen/xen_drm_front_gem.c | gem_create | 68 | 0,(-4095)-(-1) | INTERNAL | -1 | | struct xen_gem_object*(*)(struct drm_device*, ulong) |
>
> Smatch thinks that gem_create() sometimes returns NULL or error pointers
> but that's because of a bug in the unreleased version of Smatch and
> because gem_create() uses IS_ERR_OR_NULL().
>
> 141
> 142 return &xen_obj->base;
> 143 }
>
> regards,
> dan carpenter
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 15:29 ` Julia Lawall
@ 2020-04-21 17:52 ` Dan Carpenter
2020-04-21 18:59 ` Julia Lawall
0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2020-04-21 17:52 UTC (permalink / raw)
To: Julia Lawall
Cc: xen-devel, kernel-janitors, dri-devel, oleksandr_andrushchenko
On Tue, Apr 21, 2020 at 05:29:02PM +0200, Julia Lawall wrote:
>
>
> On Tue, 21 Apr 2020, Dan Carpenter wrote:
>
> > Hi Kernel Janitors,
> >
> > Here is another idea that someone could work on, fixing the
> > IS_ERR_OR_NULL() checks in the xen driver.
> >
> > The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
> > display frontend" from Apr 3, 2018, leads to the following static
> > checker warning:
> >
> > drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
> > warn: passing zero to 'ERR_CAST'
> >
> > drivers/gpu/drm/xen/xen_drm_front_gem.c
> > 133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
> > 134 size_t size)
> > 135 {
> > 136 struct xen_gem_object *xen_obj;
> > 137
> > 138 xen_obj = gem_create(dev, size);
> > 139 if (IS_ERR_OR_NULL(xen_obj))
> > 140 return ERR_CAST(xen_obj);
>
> Are the other occurrences of this also a possible problem? There are a
> few others outside of xen.
We sometimes check a parameter for IS_ERR_OR_NULL().
void free_function(struct something *p)
{
if (IS_ERR_OR_NULL(p))
return;
}
That's fine, absolutely harmless and not a bug. But if we are checking
a return value like this then probably most of the time it's invalid
code. Normally it's again like this code where we're dealing with an
impossible thing because the return is never NULL. The common bugs are
that it returns NULL to a caller which only expects error pointers or it
returns success instead of failure. But sometimes returning success can
be valid:
obj = get_feature(dev);
if (IS_ERR_OR_NULL(obj))
return PTR_ERR(obj);
It deliberately returns success because the rest of the function is
useless when we don't have the feature.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 17:52 ` Dan Carpenter
@ 2020-04-21 18:59 ` Julia Lawall
2020-04-21 19:33 ` Dan Carpenter
0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2020-04-21 18:59 UTC (permalink / raw)
To: Dan Carpenter
Cc: xen-devel, kernel-janitors, dri-devel, oleksandr_andrushchenko
On Tue, 21 Apr 2020, Dan Carpenter wrote:
> On Tue, Apr 21, 2020 at 05:29:02PM +0200, Julia Lawall wrote:
> >
> >
> > On Tue, 21 Apr 2020, Dan Carpenter wrote:
> >
> > > Hi Kernel Janitors,
> > >
> > > Here is another idea that someone could work on, fixing the
> > > IS_ERR_OR_NULL() checks in the xen driver.
> > >
> > > The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
> > > display frontend" from Apr 3, 2018, leads to the following static
> > > checker warning:
> > >
> > > drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
> > > warn: passing zero to 'ERR_CAST'
> > >
> > > drivers/gpu/drm/xen/xen_drm_front_gem.c
> > > 133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
> > > 134 size_t size)
> > > 135 {
> > > 136 struct xen_gem_object *xen_obj;
> > > 137
> > > 138 xen_obj = gem_create(dev, size);
> > > 139 if (IS_ERR_OR_NULL(xen_obj))
> > > 140 return ERR_CAST(xen_obj);
> >
> > Are the other occurrences of this also a possible problem? There are a
> > few others outside of xen.
>
> We sometimes check a parameter for IS_ERR_OR_NULL().
>
> void free_function(struct something *p)
> {
> if (IS_ERR_OR_NULL(p))
> return;
> }
>
> That's fine, absolutely harmless and not a bug. But if we are checking
> a return value like this then probably most of the time it's invalid
> code. Normally it's again like this code where we're dealing with an
> impossible thing because the return is never NULL. The common bugs are
> that it returns NULL to a caller which only expects error pointers or it
> returns success instead of failure. But sometimes returning success can
> be valid:
>
> obj = get_feature(dev);
> if (IS_ERR_OR_NULL(obj))
> return PTR_ERR(obj);
>
> It deliberately returns success because the rest of the function is
> useless when we don't have the feature.
The other cases are also with ERR_CAST:
drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c in create_udp_flow
fs/overlayfs/namei.c in ovl_index_upper
sound/soc/qcom/qdsp6/q6adm.c in q6adm_open
drivers/clk/clk.c in clk_hw_create_clk
julia
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [bug report] drm/xen-front: Add support for Xen PV display frontend
2020-04-21 18:59 ` Julia Lawall
@ 2020-04-21 19:33 ` Dan Carpenter
0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2020-04-21 19:33 UTC (permalink / raw)
To: Julia Lawall
Cc: xen-devel, kernel-janitors, dri-devel, oleksandr_andrushchenko
On Tue, Apr 21, 2020 at 08:59:09PM +0200, Julia Lawall wrote:
>
>
> On Tue, 21 Apr 2020, Dan Carpenter wrote:
>
> > On Tue, Apr 21, 2020 at 05:29:02PM +0200, Julia Lawall wrote:
> > >
> > >
> > > On Tue, 21 Apr 2020, Dan Carpenter wrote:
> > >
> > > > Hi Kernel Janitors,
> > > >
> > > > Here is another idea that someone could work on, fixing the
> > > > IS_ERR_OR_NULL() checks in the xen driver.
> > > >
> > > > The patch c575b7eeb89f: "drm/xen-front: Add support for Xen PV
> > > > display frontend" from Apr 3, 2018, leads to the following static
> > > > checker warning:
> > > >
> > > > drivers/gpu/drm/xen/xen_drm_front_gem.c:140 xen_drm_front_gem_create()
> > > > warn: passing zero to 'ERR_CAST'
> > > >
> > > > drivers/gpu/drm/xen/xen_drm_front_gem.c
> > > > 133 struct drm_gem_object *xen_drm_front_gem_create(struct drm_device *dev,
> > > > 134 size_t size)
> > > > 135 {
> > > > 136 struct xen_gem_object *xen_obj;
> > > > 137
> > > > 138 xen_obj = gem_create(dev, size);
> > > > 139 if (IS_ERR_OR_NULL(xen_obj))
> > > > 140 return ERR_CAST(xen_obj);
> > >
> > > Are the other occurrences of this also a possible problem? There are a
> > > few others outside of xen.
> >
> > We sometimes check a parameter for IS_ERR_OR_NULL().
> >
> > void free_function(struct something *p)
> > {
> > if (IS_ERR_OR_NULL(p))
> > return;
> > }
> >
> > That's fine, absolutely harmless and not a bug. But if we are checking
> > a return value like this then probably most of the time it's invalid
> > code. Normally it's again like this code where we're dealing with an
> > impossible thing because the return is never NULL. The common bugs are
> > that it returns NULL to a caller which only expects error pointers or it
> > returns success instead of failure. But sometimes returning success can
> > be valid:
> >
> > obj = get_feature(dev);
> > if (IS_ERR_OR_NULL(obj))
> > return PTR_ERR(obj);
> >
> > It deliberately returns success because the rest of the function is
> > useless when we don't have the feature.
>
> The other cases are also with ERR_CAST:
I bet these are less likely to be correct because probably the optional
feature doesn't translate to a different optional feature.
>
> drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c in create_udp_flow
This can never be NULL, but look at this code:
drivers/infiniband/hw/usnic/usnic_ib_qp_grp.c
427 if (trans_spec) {
428 qp_flow = create_and_add_flow(qp_grp,
429 trans_spec);
430 if (IS_ERR_OR_NULL(qp_flow)) {
431 status = qp_flow ? PTR_ERR(qp_flow) : -EFAULT;
432 break;
433 }
434 } else {
If the create_and_add_flow() returns NULL, that's a bug because it's not
an optional feature which can be disabled in the config etc. But this
code has been future proofed in case future users decide to write buggy
code the NULL gets changed to an error code.
Is -EFAULT the correct way to handle bugs that future programmers are
going to introduce? You have to very psychic to know the answer to
that.
> fs/overlayfs/namei.c in ovl_index_upper
This code is correct. There are actually a bunch of functions in VFS
which only return NULL and error pointers, never valid pointers. VFS
is weird like that.
> sound/soc/qcom/qdsp6/q6adm.c in q6adm_open
Never NULL. It should be IS_ERR().
> drivers/clk/clk.c in clk_hw_create_clk
This is checking a parameter so it's fine.
regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-05-08 8:47 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-21 10:45 [bug report] drm/xen-front: Add support for Xen PV display frontend Dan Carpenter
2020-04-21 11:34 ` Oleksandr Andrushchenko
2020-04-21 11:51 ` Dan Carpenter
2020-04-21 12:54 ` Oleksandr Andrushchenko
2020-05-08 7:34 ` Oleksandr Andrushchenko
2020-04-21 15:29 ` Julia Lawall
2020-04-21 17:52 ` Dan Carpenter
2020-04-21 18:59 ` Julia Lawall
2020-04-21 19:33 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox