public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
To: Ezequiel Garcia <ezequiel.garcia@imgtec.com>
Cc: Andrew Bresticker <abrestic@chromium.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	James Hartley <james.hartley@imgtec.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-pwm@vger.kernel.org>,
	Naidu Tellapati <Naidu.Tellapati@imgtec.com>,
	Arul Ramasamy <Arul.Ramasamy@imgtec.com>
Subject: Re: [PATCH v7 3/4] pdm: Imagination Technologies PDM DAC driver
Date: Thu, 8 Jan 2015 14:21:36 +0000	[thread overview]
Message-ID: <20150108142136.757eaeef@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <1420651215-3836-4-git-send-email-ezequiel.garcia@imgtec.com>

On Wed, 7 Jan 2015 14:20:14 -0300
Ezequiel Garcia <ezequiel.garcia@imgtec.com> wrote:

> From: Naidu Tellapati <Naidu.Tellapati@imgtec.com>
> 
> The Pistachio SOC from Imagination Technologies includes a Pulse Density
> Modulation DAC which produces a form of analogue output according to the
> relative density of output pulses to the intended analogue signal amplitude.
> Four PDM outputs are provided that can be used to control targets such as LCD
> backlight.


> +int img_pdm_channel_config(struct img_pdm_channel *chan, unsigned int val)
> +{
> +	struct img_pdm_device *pdm_dev;
> +
> +	if (!chan)
> +		return -EINVAL;

If this is a can't happen case then either let it crash or WARN_ON it so
that it doesn't get ignored and lead to nastier failures elsewhere

> +
> +static struct img_pdm_channel *img_pdm_channel_request(unsigned int pdm_id)
> +{
> +	unsigned int i;
> +	struct img_pdm_device *pdm_dev;
> +	struct img_pdm_channel *chan = NULL;
> +
> +	mutex_lock(&pdm_lock);
> +
> +	if (pdm_id < 0 || pdm_id >= IMG_NUM_PDM || !pdm_channels)
> +		return NULL;

You return with the mutex held in this case.



> +int img_pdm_channel_enable(struct img_pdm_channel *chan, bool state)
> +{
> +	struct img_pdm_device *pdm_dev;
> +
> +	if (!chan)
> +		return -EINVAL;

Same comment about hiding errors being bad

> +	pdm_dev = chan->pdm_dev;
> +
> +	if (!test_bit(PDM_CHANNEL_REQUESTED, &chan->flags)) {
> +		dev_err(&pdm_dev->pdev->dev, "channel not requested\n");
> +		return -EINVAL;
> +	}
> +
> +	if (state) {
> +		regmap_update_bits(pdm_dev->periph_regs,
> +				   PERIP_PWM_PDM_CONTROL,
> +				   PERIP_PWM_PDM_CONTROL_CH_MASK <<
> +				   PERIP_PWM_PDM_CONTROL_CH_SHIFT(chan->pdm_id),
> +				   1);
> +		set_bit(PDM_CHANNEL_ENABLED, &chan->flags);
> +	} else {
> +		regmap_write(pdm_dev->periph_regs,
> +			     PERIP_PDM0_VAL +
> +			     PERIP_PDM_CH_ADDR_SHIFT(chan->pdm_id), 0);
> +		regmap_update_bits(pdm_dev->periph_regs,
> +				   PERIP_PWM_PDM_CONTROL,
> +				   PERIP_PWM_PDM_CONTROL_CH_MASK <<
> +				   PERIP_PWM_PDM_CONTROL_CH_SHIFT(chan->pdm_id),
> +				   0);
> +		clear_bit(PDM_CHANNEL_ENABLED, &chan->flags);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(img_pdm_channel_enable);

You export these functions but they don't appear to do any internal
locking in them, so how is the caller expected to use them ?

If there is a reason no locking is needed in this case document why and
the assumptions.

> +
> +static ssize_t img_pdm_enable_read(struct kobject *kobj,
> +				   struct kobj_attribute *attr, char *buf)
> +{
> +	int ret;
> +	unsigned int ch_num;
> +	unsigned char kobj_name[2];
> +	struct platform_device *pdev;
> +	struct img_pdm_device *pdm_dev;
> +	struct img_pdm_channel *chan;
> +
> +	pdev = to_platform_device(kobj_to_dev(kobj->parent));
> +	pdm_dev = platform_get_drvdata(pdev);
> +	kobj_name[0] = *(kobj->name+3);
> +	kobj_name[1] = '\0';
> +
> +	ret = kstrtou32(kobj_name, 10, &ch_num);

This is C not java. 

	ch_num = kobj->name[3] - '0';

> +	if (ret) {
> +		dev_err(&pdev->dev, "could not parse channel number string\n");
> +		return ret;
> +	}
> +
> +	chan = &pdm_channels[ch_num];
> +	return sprintf(buf, "%d\n",
> +		       test_bit(PDM_CHANNEL_ENABLED, &chan->flags) ? 1 : 0);
> +}
> +
> +static ssize_t img_pdm_pulse_in_read(struct kobject *kobj,
> +				     struct kobj_attribute *attr, char *buf)
> +{
> +	int ret;
> +	unsigned int ch_num, val;
> +	unsigned char kobj_name[2];
> +	struct platform_device *pdev;
> +	struct img_pdm_device *pdm_dev;
> +	struct img_pdm_channel *chan;
> +
> +	pdev = to_platform_device(kobj_to_dev(kobj->parent));
> +	pdm_dev = platform_get_drvdata(pdev);
> +	kobj_name[0] = *(kobj->name+3);
> +	kobj_name[1] = '\0';
> +	ret = kstrtou32(kobj_name, 10, &ch_num);

Ditto (in fact why not just have a helper to range check and print the
error and share the string)

> +static ssize_t img_pdm_enable_write(struct kobject *kobj,
> +				    struct kobj_attribute *attr,
> +				    const char *buf, size_t size)
> +{
> +	int ret;
> +	unsigned int ch_num, enable;
> +	unsigned char kobj_name[2];
> +	struct platform_device *pdev;
> +	struct img_pdm_device *pdm_dev;
> +
> +	pdev = to_platform_device(kobj_to_dev(kobj->parent));
> +	pdm_dev = platform_get_drvdata(pdev);
> +
> +	kobj_name[0] = *(kobj->name+3);
> +	kobj_name[1] = '\0';
> +	ret = kstrtou32(kobj_name, 10, &ch_num);
> +	if (ret) {
> +		dev_err(&pdev->dev, "could not parse channel number string\n");
> +		return ret;
> +	}

And again

> +static ssize_t img_pdm_pulse_in_write(struct kobject *kobj,
> +				      struct kobj_attribute *attr,
> +				      const char *buf, size_t size)
> +{
> +	int ret;
> +	unsigned int pulse_in, ch_num;
> +	unsigned char kobj_name[2];
> +	struct platform_device *pdev;
> +	struct img_pdm_device *pdm_dev;
> +
> +	pdev = to_platform_device(kobj_to_dev(kobj->parent));
> +	pdm_dev = platform_get_drvdata(pdev);
> +
> +	kobj_name[0] = *(kobj->name+3);
> +	kobj_name[1] = '\0';
> +	ret = kstrtou32(kobj_name, 10, &ch_num);
> +	if (ret) {
> +		dev_err(&pdev->dev, "could not parse channel number string\n");
> +		return ret;
> +	}

and - you get the idea 8)


  reply	other threads:[~2015-01-08 14:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 17:20 [PATCH v7 0/4] Imagination Technologies PWM and PDM DACs support Ezequiel Garcia
2015-01-07 17:20 ` [PATCH v7 1/4] pwm: Imagination Technologies PWM DAC driver Ezequiel Garcia
2015-01-08 15:49   ` Vladimir Zapolskiy
2015-01-08 17:41     ` Ezequiel Garcia
2015-01-07 17:20 ` [PATCH v7 2/4] DT: pwm: Add binding document for IMG PWM DAC Ezequiel Garcia
2015-01-07 17:20 ` [PATCH v7 3/4] pdm: Imagination Technologies PDM DAC driver Ezequiel Garcia
2015-01-08 14:21   ` One Thousand Gnomes [this message]
2015-01-08 14:25     ` Ezequiel Garcia
2015-01-07 17:20 ` [PATCH v7 4/4] DT: pdm: Add binding document for IMG PDM DAC Ezequiel Garcia

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=20150108142136.757eaeef@lxorguk.ukuu.org.uk \
    --to=gnomes@lxorguk.ukuu.org.uk \
    --cc=Arul.Ramasamy@imgtec.com \
    --cc=Naidu.Tellapati@imgtec.com \
    --cc=abrestic@chromium.org \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=ezequiel.garcia@imgtec.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.hartley@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /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