public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: wei_wang@realsil.com.cn
Cc: sameo@linux.intel.com, gregkh@linuxfoundation.org,
	adam.lee@canonical.com, linux-kernel@vger.kernel.org,
	rogerable@realtek.com, devel@linuxdriverproject.org
Subject: Re: [PATCH 1/5] mfd:rtsx: Read vendor setting from config space
Date: Mon, 15 Jul 2013 17:20:46 +0300	[thread overview]
Message-ID: <20130715142046.GD5100@mwanda> (raw)
In-Reply-To: <d0a47d6128605ecd9888657ce36b81ad51116876.1373871136.git.wei_wang@realsil.com.cn>

This code has a lot of undocumented magic flags and terrible naming
in it.

> +static void rtl8411_init_settings(struct rtsx_pcr *pcr)
> +{
> +	u32 val1;
> +	u8 val2;

These names are 100% useless.  "val" means nothing.  "1" means
nothing.  "2" means nothing.  In fact, val1 is REG1 and val2 is
REG3 as opposed to REG2 as one would expect from the name so it is
misleading.

> +
> +	rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &val1);
> +	dev_dbg(&(pcr->pci->dev), "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, val1);
> +
> +	if (!(val1 & 0x1000000)) {

What is 0x1000000?  We do this test over and over so it should be
an inline function.

> +		pcr->aspm_val = (u8)((val1 >> 28) & 0x03);

The "_val" in "apsm_val" is useless.
What does "aspm" stand for?
No need to cast.  0-3 is less than 255 so casting to u8 is just
noise.
These shift masks are used over and over so they should be defined
as macros or inline functions in a header file:

#define rtl8411_reg_to_XXX(reg)		((reg >> 25) & 0x01)
#define rtl8411_reg_to_sdXXX(reg)	((reg >> 26) & 0x03)
#define rtl8411_reg_to_aspm(reg)	((reg >> 28) & 0x03)

(Choose your own names which make sense).

> +		pcr->sd30_drive_sel_1v8 = map_sd_drive((val1 >> 26) & 0x03);
> +		pcr->card_drive_sel &= 0x3F;
> +		pcr->card_drive_sel |= (u8)((val1 >> 25) & 0x01) << 6;

Again, no need to cast.  This should be a macro or an inline
function.

Pretty much the same comments apply throughout.  I'm not going to
comment on it line by line.

regards,
dan carpenter


  reply	other threads:[~2013-07-15 14:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15  6:56 [PATCH 0/5] mfd:rtsx: MFD patches for Realtek cardreader wei_wang
2013-07-15  6:56 ` [PATCH 1/5] mfd:rtsx: Read vendor setting from config space wei_wang
2013-07-15 14:20   ` Dan Carpenter [this message]
2013-07-15  6:56 ` [PATCH 2/5] mfd:rtsx: Add shutdown callback in rtsx_pci_driver wei_wang
2013-07-15  6:56 ` [PATCH 3/5] mfd:rtsx: Move some actions from rtsx_pci_init_hw to individual extra_init_hw wei_wang
2013-07-15  6:56 ` [PATCH 4/5] mfd:rtsx: Clear hardware PFM mode in rtl8411b wei_wang
2013-07-15  6:56 ` [PATCH 5/5] mfd:rtsx: Configure to enter a deeper power-saving mode in S3 wei_wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130715142046.GD5100@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=adam.lee@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rogerable@realtek.com \
    --cc=sameo@linux.intel.com \
    --cc=wei_wang@realsil.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox