Re: [PATCH] ia64: sn/pci/pcibr/pcibr_reg.c: check null pointerdereference

From: Cong Ding
Date: Mon Jan 14 2013 - 13:46:59 EST


On Mon, Jan 14, 2013 at 11:19:15AM -0700, Bjorn Helgaas wrote:
> On Mon, Jan 14, 2013 at 10:53 AM, Cong Ding <dinggnu@xxxxxxxxx> wrote:
> > we should ensure the pointer is not null before the first use, rather than
> > after it.
>
> These changes look technically correct, but the whole pcibr_reg.c file
> is ridiculously defensive programming.
>
> For example, the first two hunks are for pcireg_control_bit_clr() and
> pcireg_control_bit_set(). These functions are called only from
> pcibr_bus_fixup(), and it's impossible for it to pass a null pointer.
> It would be better to just remove the null pointer checks completely.
>
> The panics in pcibr_reg.c are dubious, too. That sort of check
> belongs higher up, e.g., in pcibr_bus_fixup() where we set up
> pcibus_info->pbi_buscommon.bs_base in the first place.
>
Thanks Bjorn, so do you think a patch like the following would be better?

- cong