[PATCH] powernv/pci: Add PHB register dump debugfs handle
Michael Ellerman
mpe at ellerman.id.au
Tue Jul 26 11:06:11 AEST 2016
Tyrel Datwyler <tyreld at linux.vnet.ibm.com> writes:
> On 07/21/2016 11:36 PM, Gavin Shan wrote:
>> On Fri, Jul 22, 2016 at 03:23:36PM +1000, Russell Currey wrote:
>>> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
>>> index 891fc4a..ada2f3c 100644
>>> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
>>> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
>>> @@ -3018,6 +3018,38 @@ static void pnv_ioda_setup_pe_seg(struct pnv_ioda_pe *pe)
>>> }
>>> }
>>>
>>> +#ifdef CONFIG_DEBUG_FS
>>> +static ssize_t pnv_pci_debug_write(struct file *filp,
>>> + const char __user *user_buf,
>>> + size_t count, loff_t *ppos)
>>> +{
>>> + struct pci_controller *hose = filp->private_data;
>>> + struct pnv_phb *phb;
>>> + int ret = 0;
>>
>> Needn't initialize @ret in advance. The code might be simpler, but it's
>> only a personal preference:
>
> I believe its actually preferred that it not be initialized in advance
> so that the tooling can warn you about conditional code paths where you
> may have forgotten to set a value.
Yeah that's right, it's preferable not to initialise it.
It helps for complex if/else/switch cases, where you might accidentally
have a path where you return without giving ret the right value.
The other case is when someone modifies your code. For example if you
have:
int ret;
if (foo)
ret = do_foo();
else
ret = 1;
return ret;
And then you add a case to the if:
if (foo)
ret = do_foo();
else if (bar)
do_bar();
else
ret = 1;
The compiler will warn you that in the bar case you forget to initialise
ret. Whereas if you initialised ret at the start then the compiler can't
help you.
There are times when it's cleaner to initialise the value at the start,
eg. if you have many error cases and only one success case. But that
should be a deliberate choice.
cheers
More information about the Linuxppc-dev
mailing list