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: cjb@laptop.org, sameo@linux.intel.com, arnd@arndb.de,
	oakad@yahoo.com, gregkh@linuxfoundation.org,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	bp@alien8.de, devel@linuxdriverproject.org
Subject: Re: [PATCH v5 1/3] drivers/mfd: Add realtek pcie card reader driver
Date: Mon, 10 Sep 2012 17:47:32 +0300	[thread overview]
Message-ID: <20120910144732.GK19396@mwanda> (raw)
In-Reply-To: <3bdd140d1927e579fd3e2d98ecf6332650f36d6f.1347256563.git.wei_wang@realsil.com.cn>


I just had a couple few style comments is all, nothing that couldn't
be fixed in a later patch.

On Mon, Sep 10, 2012 at 04:03:29PM +0800, wei_wang@realsil.com.cn wrote:
> +static int rts5209_extra_init_hw(struct rtsx_pcr *pcr)
> +{
> +	return 0;
> +}

It would be nicer if the caller checked whether this pointer was
NULL and only called it if it needed to.

> +
> +static int rts5209_optimize_phy(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xB966);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

static int rts5209_optimize_phy(struct rtsx_pcr *pcr)
{
	return rtsx_pci_write_phy_register(pcr, 0x00, 0xB966);
}

> +
> +static int rts5209_turn_on_led(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFD58, 0x01, 0x00);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

Same.

> +
> +static int rts5209_turn_off_led(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFD58, 0x01, 0x01);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}
> +

Same.

> +static int rts5209_enable_auto_blink(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0xFF, 0x0D);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}
> +

Same.

> +static int rts5209_disable_auto_blink(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, CARD_AUTO_BLINK, 0x08, 0x00);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}
> +

Same.

[snip ]

> +static int rts5229_extra_init_hw(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	rtsx_pci_init_cmd(pcr);
> +
> +	/* Switch LDO3318 source from DV33 to card_3v3 */
> +	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFE78, 0x03, 0x00);
> +	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFE78, 0x03, 0x01);
> +	/* LED shine disabled, set initial shine cycle period */
> +	rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, 0xFC1E, 0x0F, 0x02);
> +
> +	err = rtsx_pci_send_cmd(pcr, 100);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;

	return rtsx_pci_send_cmd(pcr, 100);

> +}
> +
> +static int rts5229_optimize_phy(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	/* Optimize RX sensitivity */
> +	err = rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

Same.

> +
> +static int rts5229_turn_on_led(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFC1F, 0x02, 0x02);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}
> +

Same.

> +static int rts5229_turn_off_led(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFC1F, 0x02, 0x00);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

Same.

> +
> +static int rts5229_enable_auto_blink(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFC1E, 0x08, 0x08);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

Same.

> +
> +static int rts5229_disable_auto_blink(struct rtsx_pcr *pcr)
> +{
> +	int err;
> +
> +	err = rtsx_pci_write_register(pcr, 0xFC1E, 0x08, 0x00);
> +	if (err < 0)
> +		return err;
> +
> +	return 0;
> +}

Same.

[ snip ].

> +static DEFINE_PCI_DEVICE_TABLE(rtsx_pci_ids) = {
> +	{ 0x10EC, 0x5209, PCI_ANY_ID, PCI_ANY_ID,
> +		PCI_CLASS_OTHERS << 16, 0xFF0000 },
> +	{ 0x10EC, 0x5229, PCI_ANY_ID, PCI_ANY_ID,
> +		PCI_CLASS_OTHERS << 16, 0xFF0000 },

If you want to fit it all on one line you could do:

	{ PCI_DEVICE(0x10EC, 0x5229), PCI_CLASS_OTHERS << 16, 0xFF0000 },

It's weird that this is the only driver in the kernel which uses
the PCI_CLASS_OTHERS macro like this.

[ snip ]

> +int rtsx_pci_read_register(struct rtsx_pcr *pcr, u16 addr, u8 *data)
> +{
> +	u32 val = 2 << 30;
> +	int i;
> +
> +	val |= (u32)(addr & 0x3FFF) << 16;
> +	rtsx_pci_writel(pcr, RTSX_HAIMR, val);
> +
> +	for (i = 0; i < MAX_RW_REG_CNT; i++) {
> +		val = rtsx_pci_readl(pcr, RTSX_HAIMR);
> +		if ((val & (1 << 31)) == 0)

When we set this we do "2 << 30" but when we test it we do
"1 << 31".  It would be nice to be consistent.

> +int rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
> +{
> +	int err, i, finished = 0;
> +	u16 data = 0;
            ^^^^^^^^
Not needed.

> +	u8 *ptr, tmp;
> +

[ snip ]
> +	spin_lock_irqsave(&pcr->lock, flags);
> +
> +	if (pcr->trans_result == TRANS_RESULT_FAIL) {
> +		err = -EINVAL;
> +		spin_unlock_irqrestore(&pcr->lock, flags);
> +		goto out;
> +	} else if (pcr->trans_result == TRANS_NO_DEVICE) {
> +		err = -ENODEV;
> +		spin_unlock_irqrestore(&pcr->lock, flags);
> +		goto out;
> +	}
> +
> +	spin_unlock_irqrestore(&pcr->lock, flags);


Could be written like:
	if (pcr->trans_result == TRANS_RESULT_FAIL)
		err = -EINVAL;
	else if (pcr->trans_result == TRANS_NO_DEVICE)
		err = -ENODEV;

	spin_unlock_irqrestore(&pcr->lock, flags);

> +
> +out:
> +	spin_lock_irqsave(&pcr->lock, flags);
> +	pcr->done = NULL;
> +	spin_unlock_irqrestore(&pcr->lock, flags);
> +

[snip]

> +	pcr->slots = kzalloc(sizeof(struct rtsx_slot) * pcr->num_slots,
> +			GFP_KERNEL);

You could use kcalloc() here.

regards,
dan carpenter

  reply	other threads:[~2012-09-10 14:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-10  8:03 [PATCH v5 0/3] Add modules to support realtek PCIE card reader wei_wang
2012-09-10  8:03 ` [PATCH v5 1/3] drivers/mfd: Add realtek pcie card reader driver wei_wang
2012-09-10 14:47   ` Dan Carpenter [this message]
2012-09-10  8:03 ` [PATCH v5 2/3] drivers/mmc: Add realtek pcie sdmmc host driver wei_wang
2012-09-10  8:03 ` [PATCH v5 3/3] drivers/memstick: Add realtek pcie memstick " wei_wang
2012-09-10  9:21 ` [PATCH v5 0/3] Add modules to support realtek PCIE card reader Dan Carpenter
2012-09-10  9:25   ` wwang
2012-09-10 14:00     ` Dan Carpenter

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=20120910144732.GK19396@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=cjb@laptop.org \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=oakad@yahoo.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