Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp2297495imc; Fri, 22 Feb 2019 23:55:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IbzmjzAOgSBvoWJNBdwp3bcpCghtBwwlBUSQfk1yjSntcajukd/2bzib97NbHDJoVTSmXFe X-Received: by 2002:a62:3a47:: with SMTP id h68mr8222814pfa.202.1550908548967; Fri, 22 Feb 2019 23:55:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550908548; cv=none; d=google.com; s=arc-20160816; b=t55J1ANt3CejBgVSMcQA0NrfPmEFfPlepCB7OWnIqi7jdHXff2iHHrR8nd++aIXf2h +awYc+wcynPJUapNwwqSUWR9RdU2aN4rUeIQkyHEV+7+ff6nqsg02cqUupkILvtVLKjv rXcssK7k/R5MXJ1p0w3ReJE7kWgpKIc1jXbkX8Kn7bOw+VW+NBnJk+Hlw3hGC0uXoZ+9 1oAv03ncaakrk/h+KJM09hG9TPSlnVmu7JU3/fK6qi2cOuCz3qBiuYWuT8SrQxRSNGZH DKQPQndQVQeBd2cJ8J8FkjCCRXz/D+EbmjV/vMWsVE+r76nYtEBH3JLrdNMHgk6Xobx2 URag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=p74/hmz/QyKJHsbEXYThOyI6ubIkQDgZgtiq1/d1w5I=; b=wQIZg4N+ZRKv9v76QtqYeCqJfr8MISHZGRfm14npSzXgyjgTGG/tKGAVAtn8dujzU/ DaTP5TxCRB6l9OXVjrKD0c3w9swFVJDw94fT06yeref2k+h09b2xtfEyVT7neSocTYTY S4xW//0AezH99iqmobZtunBHNbgrS7gKEGK/GnENCEBIX4bxFWdJMA8ndaIx8N9t0gky QvJsjo/hr25pOqKSjCpNMdK8QqUwxaxfwyF5hqPIa5GskXlWOvIvU+1j2Y8xw0JJdOaT AXxZExDK6nXB2uLeqXKv/msHoWmNtK5LpDg7WK5G2VGkh/zpwTpvxGjWFLYZ1QHvXt+i CPJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@schinagl.nl header.s=7of9 header.b=cRlFDh94; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=schinagl.nl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si3384423plg.408.2019.02.22.23.55.31; Fri, 22 Feb 2019 23:55:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@schinagl.nl header.s=7of9 header.b=cRlFDh94; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=schinagl.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbfBWHzL (ORCPT + 99 others); Sat, 23 Feb 2019 02:55:11 -0500 Received: from 7of9.schinagl.nl ([62.251.20.244]:37098 "EHLO 7of9.schinagl.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbfBWHzL (ORCPT ); Sat, 23 Feb 2019 02:55:11 -0500 Received: from [10.2.10.179] (unknown [10.2.10.179]) by 7of9.schinagl.nl (Postfix) with ESMTPA id E63D9B4EFF7; Sat, 23 Feb 2019 08:55:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=schinagl.nl; s=7of9; t=1550908506; bh=fTvPyVgW9O9vlu3A+EhIWigHjkUscvOJgEbcxfOakdI=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=cRlFDh94FD+80jJicLpidXF5m2qNi8IYR+VohaDMeflGqR7dqKjF/YKh7cfdsa/y5 pw1ROEDn+yqFLtJoC8bV03l6miecvMZInpO/Z4Vc48c+rqDlblcqgl0CzymLCvT65m pC9UW8S3Laj4m5EUuBgMBHk9t/5YJcLEcxk27/Cs= Subject: Re: [PATCH] regulator: axp20x: Get rid of AXP20X_xxx_START/END/STEPS defines To: Mark Brown , Axel Lin Cc: Chen-Yu Tsai , Priit Laes , Liam Girdwood , LKML References: <20190220165013.12774-1-axel.lin@ingics.com> <24E35288-677D-4223-B94A-52A4F37792A8@schinagl.nl> <20190221094237.GA5970@sirena.org.uk> From: Olliver Schinagl Message-ID: Date: Sat, 23 Feb 2019 08:55:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <20190221094237.GA5970@sirena.org.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-02-2019 10:42, Mark Brown wrote: > On Thu, Feb 21, 2019 at 08:22:53AM +0800, Axel Lin wrote: >> Olliver Schinagl 於 2019年2月21日 週四 上午6:57寫道: >>> On February 20, 2019 5:50:13 PM GMT+01:00, Axel Lin wrote: >>>> The AXP20X_xxx_START/END/STEPS defines make the code hard to read and >>>> very hard to check the linear range settings because it needs to check >>>> the defines one-by-one. >>>> The original code without the defines is very good in readability >>>> as the meaning of each field of REGULATOR_LINEAR_RANGE is clear. >>>> So I suggest to get rid of AXP20X_xxx_START/END/STEPS defines. >>> Are you suggesting that magic values and hex numbers are more readable? >> For example: >> static const struct regulator_linear_range axp803_dcdc234_ranges[] = { >> REGULATOR_LINEAR_RANGE(500000, 0x0, 0x46, 10000), >> REGULATOR_LINEAR_RANGE(1220000, 0x47, 0x4b, 20000), >> }; >> Above looks very clear to me as it describes the linear ranges: >> 1st linear range: min_uV is 500000, from selector 0 ~ 0x46, the uV_step is 10000 >> 2nd linear range: min_uV is 1220000, from selector 0x47 ~ 0x4b, the >> uV_step is 20000 >> And it's easy to check the min_sel and max_sel in each linear range. > Frankly I tend to agree with Axel here - the defines are used in exactly > one place so their main impact is that you can't read the ranges > directly in the array but have to jump around to read through the > defines. The number of times the defines are used, are of course no reason for it to be a bad thing. Defines should certainly not be thought of as a tool to only reduce duplicity of course. Also being consistent where others do have multiple invocations makes sense. I will not disagree that it may be extra work to look up the define (especially if there is no tool tip or split view in the editor) but reading the whole lot of code, with only the magic values, you still have to look up the meaning of each magic value, have to guess which one has the same meaning etc. Further more, I do believe far more people reading will find an define to be more descriptive to read. Whoever needs to actually go in and fix/change things. Also, how many steps are in the first or second regulator ranges? which bits are these exactly? Etc etc, you still have to use your mind to figure things out. Finally, while some people live and breath hexadecimals and bitmasks, others just see magic values. So having something readable there, may make it harder for the one that needs to work on it (which hopefully is almost never, as these things are not very dynamic/commonly changing) but passers by see readable text and understand what is happening at a glance. Which is why we where taught not to use magic values in the first place :)