mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: "Jon Arne Jørgensen" <jonarne@jonarne.no>
Cc: "Bjørn Mork" <bjorn@mork.no>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	elezegarcia@gmail.com
Subject: Re: [RFC V1 5/8] smi2021: Add smi2021_video.c
Date: Wed, 20 Mar 2013 11:09:27 +0100	[thread overview]
Message-ID: <201303201109.27443.hverkuil@xs4all.nl> (raw)
In-Reply-To: <20130320100636.GM17291@dell.arpanet.local>

On Wed 20 March 2013 11:06:36 Jon Arne Jørgensen wrote:
> On Mon, Mar 18, 2013 at 09:58:32AM +0100, Bjørn Mork wrote:
> > Hans Verkuil <hverkuil@xs4all.nl> writes:
> > 
> > >> +/*
> > >> + *
> > >> + * The device delivers data in chunks of 0x400 bytes.
> > >> + * The four first bytes is a magic header to identify the chunks.
> > >> + *	0xaa 0xaa 0x00 0x00 = saa7113 Active Video Data
> > >> + *	0xaa 0xaa 0x00 0x01 = PCM - 24Bit 2 Channel audio data
> > >> + */
> > >> +static void process_packet(struct smi2021_dev *dev, u8 *p, int len)
> > >> +{
> > >> +	int i;
> > >> +	u32 *header;
> > >> +
> > >> +	if (len % 0x400 != 0) {
> > >> +		printk_ratelimited(KERN_INFO "smi2021::%s: len: %d\n",
> > >> +				__func__, len);
> > >> +		return;
> > >> +	}
> > >> +
> > >> +	for (i = 0; i < len; i += 0x400) {
> > >> +		header = (u32 *)(p + i);
> > >> +		switch (__cpu_to_be32(*header)) {
> > >
> > > That's not right. You probably mean __be32_to_cpu, that makes more sense.
> > >
> > >> +		case 0xaaaa0000: {
> > >> +			parse_video(dev, p+i+4, 0x400-4);
> > >> +			break;
> > >> +		}
> > >> +		case 0xaaaa0001: {
> > >> +			smi2021_audio(dev, p+i+4, 0x400-4);
> > >> +			break;
> > >> +		}
> > 
> > This could be just me, but I would have done it like this to take
> > advantage of compile time constant conversions (and also dropping the
> > noisy extra {}s):
> > 
> > 		switch (*header) {
> > 		case cpu_to_be32(0xaaaa0000):
> > 			parse_video(dev, p+i+4, 0x400-4);
> > 			break;
> > 		case cpu_to_be32(0xaaaa0001):
> > 			smi2021_audio(dev, p+i+4, 0x400-4);
> > 			break;
> >                 ..
> > 
> > 
> > >From the name of the function I assume the difference may actually be
> > measurable here if this runs for every processed packet.
> > 
> > 
> 
> You are both right, I will have a second look at this code.
> I guess I'll try to implement Bjørns suggestion.
> 
> As I'm working with a byte-array, I could probably change this code to:
> 
> 		if (header[0] == 0xaa && header[1] == 0xaa
> 			&& header[2] == 0x00 && header[3] == 0x00) {
> 
> 			{...}
> 
> 		} else if (header[0] == 0xaa && header[1] == 0xaa
> 			&& header[2] == 0x00 && header[3] == 0x01) {
> 		
> 			{...}
> 		}
> 
> But I hope you agree that the switch statement is cleaner?
> 
> (I just find it hard to wrap my head around the big vs. little endian
> differences when dealing with hexadecimal integer notation :) )

Bjørn's solution is best in this case.

Regards,

	Hans

> 
> > Bjørn
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

  reply	other threads:[~2013-03-20 10:19 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-14 14:06 [RFC V1 0/8] Add a driver for somagic smi2021 Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 1/8] smi2021: Add the header file Jon Arne Jørgensen
2013-03-15 12:13   ` Ezequiel Garcia
2013-03-17 20:16     ` Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 2/8] smi2021: Add smi2021_main.c Jon Arne Jørgensen
2013-03-15 12:20   ` Ezequiel Garcia
2013-03-17 20:14     ` Jon Arne Jørgensen
2013-03-18  7:58   ` Hans Verkuil
2013-03-20  9:30     ` Jon Arne Jørgensen
2013-03-18  8:30   ` Hans Verkuil
2013-03-20  9:31     ` Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 3/8] smi2021: Add smi2021_i2c.c Jon Arne Jørgensen
2013-03-15 12:27   ` Ezequiel Garcia
2013-03-17 19:59     ` Jon Arne Jørgensen
2013-03-18  8:04   ` Hans Verkuil
2013-03-20  9:32     ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 4/8] smi2021: Add smi2021_v4l2.c Jon Arne Jørgensen
2013-03-15 12:33   ` Ezequiel Garcia
2013-03-17 20:27     ` Jon Arne Jørgensen
2013-03-18  8:12   ` Hans Verkuil
2013-03-20  9:43     ` Jon Arne Jørgensen
2013-03-20 10:07       ` Hans Verkuil
2013-03-18  8:29   ` Hans Verkuil
2013-03-20  9:48     ` Jon Arne Jørgensen
2013-03-20 10:10       ` Hans Verkuil
2013-03-20 10:16         ` Jon Arne Jørgensen
2013-03-20 10:21           ` Hans Verkuil
2013-03-20 11:09             ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 5/8] smi2021: Add smi2021_video.c Jon Arne Jørgensen
2013-03-15 12:40   ` Ezequiel Garcia
2013-03-17 20:19     ` Jon Arne Jørgensen
2013-03-18  8:17   ` Hans Verkuil
2013-03-18  8:58     ` Bjørn Mork
2013-03-20 10:06       ` Jon Arne Jørgensen
2013-03-20 10:09         ` Hans Verkuil [this message]
2013-03-14 14:07 ` [RFC V1 6/8] smi2021: Add smi2021_audio.c Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 7/8] smi2021: Add smi2021_bl.c Jon Arne Jørgensen
2013-03-18  9:31   ` Bjørn Mork
2013-03-20  8:59     ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 8/8] smi2021: Add Kconfig and Makefiles Jon Arne Jørgensen
2013-03-15 12:08 ` [RFC V1 0/8] Add a driver for somagic smi2021 Ezequiel Garcia
2013-03-17 20:01   ` Jon Arne Jørgensen
2013-03-18  0:05     ` Ezequiel Garcia
2013-03-20 10:11       ` Jon Arne Jørgensen

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=201303201109.27443.hverkuil@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=bjorn@mork.no \
    --cc=elezegarcia@gmail.com \
    --cc=jonarne@jonarne.no \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®