Re: [PATCH v4 07/23] ata: libahci_platform: Convert to using devm bulk clocks API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 16, 2022 at 09:23:28AM +0900, Damien Le Moal wrote:
> On 2022/06/16 5:45, Serge Semin wrote:
> [...]
> >>> +		hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL);
> >>> +		if (!hpriv->clks) {
> >>> +			rc = -ENOMEM;
> >>> +			goto err_out;
> >>> +		}
> >>> +		hpriv->clks->clk = devm_clk_get_optional(dev, NULL);
> > 
> >>> +		if (IS_ERR(hpriv->clks->clk)) {
> >>> +			rc = PTR_ERR(hpriv->clks->clk);
> >>> +			goto err_out;
> >>> +		} else if (hpriv->clks->clk) {
> >>
> >> Nit: the else is not needed here.
> > 
> > Well, it depends on what you see behind it. I see many reasons to keep
> > it and only one tiny reason to drop it. Keeping it will improve the
> > code readability and maintainability like having a more natural
> > execution flow representation, thus clearer read-flow (else part as
> > exception to the if part), less modifications should the goto part is
> > changed/removed, a more exact program flow representation can be used
> > by the compiler for some internal optimizations, it's one line shorter
> > than the case we no 'else' here. On the other hand indeed we can drop
> > it since if the conditional statement is true, the code afterwards
> > won't be executed due to the goto operator. But as I see it dropping
> > the else operator won't improve anything, but vise-versa will worsen
> > the code instead. So if I get to miss something please justify why you
> > want it being dropped, otherwise I would rather preserve it.
> 
> An else after a goto or return is never necessary and in my opinion makes the
> code harder to read. I am not interested in debating this in general anyway. For
> this particular case, the code would be:
> 
> 		hpriv->clks->clk = devm_clk_get_optional(dev, NULL);
> 		if (IS_ERR(hpriv->clks->clk)) {
> 			/* Error path */
> 			rc = PTR_ERR(hpriv->clks->clk);
> 			goto err_out;
> 		}
> 
> 		/* Normal path */
> 		if (hpriv->clks->clk) {
> 			...
> 		}
> 
> Which in my opinion is a lot easier to understand compared to having to parse
> the if/else if and figure out which case in that sequence is normal vs error.
> 

> As noted, this is a nit. If you really insist, keep that else if.

Ok. I'll leave it as is then.

Thanks
-Sergey

> 
> > 
> > -Sergey
> > 
> >>
> >>> +			hpriv->clks->id = __clk_get_name(hpriv->clks->clk);
> >>> +			hpriv->n_clks = 1;
> >>>  		}
> >>> -		hpriv->clks[i] = clk;
> >>>  	}
> >>>  
> >>>  	hpriv->ahci_regulator = devm_regulator_get(dev, "ahci");
> >>
> >>
> >> -- 
> >> Damien Le Moal
> >> Western Digital Research
> 
> 
> -- 
> Damien Le Moal
> Western Digital Research



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux