public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: ltp-list@lists.sourceforge.net
Cc: Alexey Kodanev <alexey.kodanev@oracle.com>, vasily.isaenko@oracle.com
Subject: Re: [LTP] [PATCH v6] fw_load: new test of device firmware loading
Date: Tue, 2 Jul 2013 16:50:55 -0400	[thread overview]
Message-ID: <201307021650.56483.vapier@gentoo.org> (raw)
In-Reply-To: <1372765421-2934-1-git-send-email-alexey.kodanev@oracle.com>


[-- Attachment #1.1: Type: Text/Plain, Size: 3531 bytes --]

On Tuesday 02 July 2013 07:43:41 Alexey Kodanev wrote:
> --- /dev/null
> +++ b/testcases/kernel/firmware/Makefile
>
> +ifeq ($(WITH_MODULES),yes)
> +PROCEED ?= $(shell expr $(LINUX_VERSION_MAJOR) '>' $(REQ_VERSION_MAJOR))

use `test` rather than `expr`.  people are more familiar with that.

	test $(LINUX_VERSION_MAJOR) -gt $(REQ_VERSION_MAJOR)

> --- /dev/null
> +++ b/testcases/kernel/firmware/fw_load_kernel/Makefile
>
> +MAKE_TARGETS	:= ltp_fw_load.ko
> +ltp_fw_load.ko: ltp_fw_load.c
> +	-$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir)
> +	-mv ltp_fw_load.ko ltp_fw_load.ko~
> +	-$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir) clean
> +	-mv ltp_fw_load.ko~ ltp_fw_load.ko

what's with ignoring the exit status of all these ?  and why clean when you're 
done ?  doesn't seem like you'd want to do either of these.

> --- /dev/null
> +++ b/testcases/kernel/firmware/fw_load_kernel/ltp_fw_load.c

> +/* read and print firmware data */
> +static int fw_read(const u8 *data, size_t size);
> +
> +static void device_release(struct device *dev);
> +
> +static struct device tdev = {
> +	.init_name	= TCID,
> +	.release	= device_release,
> +};
> +
> +static int try_request_fw(const char *name);
> +
> +/* print test result to sysfs file */
> +static ssize_t sys_result(struct device *dev,
> +	struct device_attribute *attr, char *buf);
> +static DEVICE_ATTR(result, S_IRUSR, sys_result, NULL);
> +
> +/*
> + * get the number of firmware files and
> + * perform firmware requests
> + */
> +static ssize_t sys_fwnum(struct device *dev,
> +	struct device_attribute *attr, const char *buf, size_t count);
> +static DEVICE_ATTR(fwnum, S_IWUSR, NULL, sys_fwnum);

generally it's preferable to organize the code such that forward decls aren't 
even necessary.  seems like it'd be trivial to reorganize this file as such.

> +static int test_init(void)
> +{
> +	int err;
> +
> +	err = device_register(&tdev);
> +	if (err) {
> +		pr_err(TCID ": Unable to register device\n");

define pr_fmt at the top of the file rather than manually inserting TCID in 
every call point

> +	err = device_create_file(&tdev, &dev_attr_result);
> +	if (err != 0)

typically it's better to just do:
	if (err)

> +		pr_info(TCID ": Can't create sysfs file 'result'\n");

pr_err

> +	err = device_create_file(&tdev, &dev_attr_fwnum);
> +	if (err != 0)
> +		pr_info(TCID ": Can't create sysfs file 'fwnum'\n");

if 'result' failed but 'fwnum' passed, this func incorrectly returns 0

you should have this code return immediately, and if fwnum fails, have it call 
device_remove_file on 'result'

> +static ssize_t sys_fwnum(struct device *dev,
> +	struct device_attribute *attr,  const char *buf, size_t count)
> +{
> +	int err, fw_num = 0;
> +
> +	sscanf(buf, "%d", &fw_num);
> +	if (fw_num <= 0) {
> +		pr_err(TCID ": Unexpected number of firmwares '%d'", fw_num);
> +		return count;
> +	}
> +	for (fw = 0; fw < fw_num; ++fw) {
> +		char name[max_name];
> +		snprintf(name, max_name, "n%d_%s", fw, fw_name);
> +		err = try_request_fw(name);
> +		test_result |= (err == 0) << fw;

mmm and what if fw_num > sizeof(test_result) ?

> +static int fw_read(const u8 *data, size_t size)
> +{
> +	size_t i;
> +	pr_info(TCID ": Firmware has size '%d'\n", (unsigned int) size);

don't cast.  use a proper format string: %zu.

> +module_init(test_init);
> +module_exit(test_exit);

i'd move those to below the respective func rather than at the bottom of the 
file
-mike

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 184 bytes --]

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2013-07-02 20:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02 11:43 [LTP] [PATCH v6] fw_load: new test of device firmware loading Alexey Kodanev
2013-07-02 18:24 ` chrubis
2013-07-02 20:50 ` Mike Frysinger [this message]
2013-07-03  8:02   ` alexey.kodanev
2013-07-03 10:33     ` chrubis
     [not found]       ` <201307031300.00679.vapier@gentoo.org>
     [not found]         ` <51D548FC.9010003@oracle.com>
2013-07-10 11:14           ` chrubis
     [not found]           ` <51DBCD1E.3040303@oracle.com>
2013-07-10 11:43             ` chrubis
2013-07-03 11:08   ` chrubis

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=201307021650.56483.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=alexey.kodanev@oracle.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=vasily.isaenko@oracle.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