* [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg
@ 2015-09-01 10:21 Colin King
2015-09-01 10:35 ` Geert Uytterhoeven
2015-09-01 17:20 ` Geoff Levand
0 siblings, 2 replies; 5+ messages in thread
From: Colin King @ 2015-09-01 10:21 UTC (permalink / raw)
To: Geoff Levand, linuxppc-dev; +Cc: linux-kernel
From: Colin Ian King <colin.king@canonical.com>
On the unlikely event that drv is null, the current code will
perform a null pointer dereference with it when printing a dev_dbg
message. Instead, the BUG_ON check on drv should be performed
before we emit the dev_dbg message.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/ps3/ps3-vuart.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
index d6db822..632701a 100644
--- a/drivers/ps3/ps3-vuart.c
+++ b/drivers/ps3/ps3-vuart.c
@@ -1000,12 +1000,11 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
drv = ps3_system_bus_dev_to_vuart_drv(dev);
+ BUG_ON(!drv);
dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
drv->core.core.name);
- BUG_ON(!drv);
-
if (dev->port_number >= PORT_COUNT) {
BUG();
return -EINVAL;
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg
2015-09-01 10:21 [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg Colin King
@ 2015-09-01 10:35 ` Geert Uytterhoeven
2015-09-01 10:38 ` Colin Ian King
2015-09-01 17:20 ` Geoff Levand
1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2015-09-01 10:35 UTC (permalink / raw)
To: Colin King
Cc: Geoff Levand, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Hi Colin,
On Tue, Sep 1, 2015 at 12:21 PM, Colin King <colin.king@canonical.com> wrote:
> On the unlikely event that drv is null, the current code will
> perform a null pointer dereference with it when printing a dev_dbg
> message. Instead, the BUG_ON check on drv should be performed
> before we emit the dev_dbg message.
What about just removing the BUG_ON()?
The system will crash anyway, providing a backtrace.
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/ps3/ps3-vuart.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
> index d6db822..632701a 100644
> --- a/drivers/ps3/ps3-vuart.c
> +++ b/drivers/ps3/ps3-vuart.c
> @@ -1000,12 +1000,11 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
> dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
>
> drv = ps3_system_bus_dev_to_vuart_drv(dev);
> + BUG_ON(!drv);
>
> dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
> drv->core.core.name);
>
> - BUG_ON(!drv);
> -
> if (dev->port_number >= PORT_COUNT) {
> BUG();
> return -EINVAL;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg
2015-09-01 10:35 ` Geert Uytterhoeven
@ 2015-09-01 10:38 ` Colin Ian King
2015-09-01 11:28 ` Geert Uytterhoeven
0 siblings, 1 reply; 5+ messages in thread
From: Colin Ian King @ 2015-09-01 10:38 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Geoff Levand, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
On 01/09/15 11:35, Geert Uytterhoeven wrote:
> Hi Colin,
>
> On Tue, Sep 1, 2015 at 12:21 PM, Colin King <colin.king@canonical.com> wrote:
>> On the unlikely event that drv is null, the current code will
>> perform a null pointer dereference with it when printing a dev_dbg
>> message. Instead, the BUG_ON check on drv should be performed
>> before we emit the dev_dbg message.
>
> What about just removing the BUG_ON()?
>
> The system will crash anyway, providing a backtrace.
I personally think a BUG_ON() shows intention to try to catch an
unexpected issue in a standard way as opposed to just removing it and
then hitting an issue with a null ptr deference.
>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>> drivers/ps3/ps3-vuart.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
>> index d6db822..632701a 100644
>> --- a/drivers/ps3/ps3-vuart.c
>> +++ b/drivers/ps3/ps3-vuart.c
>> @@ -1000,12 +1000,11 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
>> dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
>>
>> drv = ps3_system_bus_dev_to_vuart_drv(dev);
>> + BUG_ON(!drv);
>>
>> dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
>> drv->core.core.name);
>>
>> - BUG_ON(!drv);
>> -
>> if (dev->port_number >= PORT_COUNT) {
>> BUG();
>> return -EINVAL;
>
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg
2015-09-01 10:38 ` Colin Ian King
@ 2015-09-01 11:28 ` Geert Uytterhoeven
0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2015-09-01 11:28 UTC (permalink / raw)
To: Colin Ian King
Cc: Geoff Levand, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org
Hi Colin,
On Tue, Sep 1, 2015 at 12:38 PM, Colin Ian King
<colin.king@canonical.com> wrote:
> On 01/09/15 11:35, Geert Uytterhoeven wrote:
>> On Tue, Sep 1, 2015 at 12:21 PM, Colin King <colin.king@canonical.com> wrote:
>>> On the unlikely event that drv is null, the current code will
>>> perform a null pointer dereference with it when printing a dev_dbg
>>> message. Instead, the BUG_ON check on drv should be performed
>>> before we emit the dev_dbg message.
>>
>> What about just removing the BUG_ON()?
>>
>> The system will crash anyway, providing a backtrace.
>
> I personally think a BUG_ON() shows intention to try to catch an
> unexpected issue in a standard way as opposed to just removing it and
> then hitting an issue with a null ptr deference.
I think this BUG_ON() was purely used during development of the ps3_vuart
framework.
Note that the corresponding platform_drv_probe() also just dereferences its
driver pointer.
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>> ---
>>> drivers/ps3/ps3-vuart.c | 3 +--
>>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
>>> index d6db822..632701a 100644
>>> --- a/drivers/ps3/ps3-vuart.c
>>> +++ b/drivers/ps3/ps3-vuart.c
>>> @@ -1000,12 +1000,11 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
>>> dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
>>>
>>> drv = ps3_system_bus_dev_to_vuart_drv(dev);
>>> + BUG_ON(!drv);
>>>
>>> dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
>>> drv->core.core.name);
>>>
>>> - BUG_ON(!drv);
>>> -
>>> if (dev->port_number >= PORT_COUNT) {
>>> BUG();
>>> return -EINVAL;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg
2015-09-01 10:21 [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg Colin King
2015-09-01 10:35 ` Geert Uytterhoeven
@ 2015-09-01 17:20 ` Geoff Levand
1 sibling, 0 replies; 5+ messages in thread
From: Geoff Levand @ 2015-09-01 17:20 UTC (permalink / raw)
To: Colin King; +Cc: linuxppc-dev, linux-kernel
On Tue, 2015-09-01 at 11:21 +0100, Colin King wrote:
> On the unlikely event that drv is null, the current code will
> perform a null pointer dereference with it when printing a dev_dbg
> message. Instead, the BUG_ON check on drv should be performed
> before we emit the dev_dbg message.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
I applied this to my ps3-linux repo. I can update it if you decide to
do the other fixes Geert mentioned.
-Geoff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-09-01 17:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-01 10:21 [PATCH] ps3-vuart: BUG_ON on null drv before dereferencing it on dev_dbg Colin King
2015-09-01 10:35 ` Geert Uytterhoeven
2015-09-01 10:38 ` Colin Ian King
2015-09-01 11:28 ` Geert Uytterhoeven
2015-09-01 17:20 ` Geoff Levand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).