lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <47F1A675.3050204@codemonkey.ws>
Date:	Mon, 31 Mar 2008 22:05:25 -0500
From:	Anthony Liguori <anthony@...emonkey.ws>
To:	"Darrick J. Wong" <djwong@...ibm.com>
CC:	"Mark M. Hoffman" <mhoffman@...htlink.com>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	lm-sensors <lm-sensors@...sensors.org>
Subject: Re: [PATCH 2/2] ibmaem: New driver for power/energy meters in IBM
   System X hardware

Darrick J. Wong wrote:
> New driver to read energy, power, and temperature meters in various
> IBM System X hardware.

<snip>

> +/* sysfs support functions */
> +/* Discover sensors on an AEM device */
> +#define AEM_FIND_SENSORS(type) \
> +static int type##_find_sensors(struct type##_data *data) \
> +{ \
> +	struct aem_ro_sensor_template *ro; \
> +	struct aem_rw_sensor_template *rw; \
> +	int err, idx; \
> +\
> +	/* Set up read-only sensors */ \
> +	ro = type##_ro_sensors; \
> +	idx = 0; \
> +	while (ro->label) { \
> +		data->sensors[idx].dev_attr.attr.name = ro->label; \
> +		data->sensors[idx].dev_attr.attr.mode = S_IRUGO; \
> +		data->sensors[idx].dev_attr.show = ro->show; \
> +		data->sensors[idx].index = ro->index; \
> +\
> +		err = device_create_file(&data->fw.pdev->dev, \
> +					 &data->sensors[idx].dev_attr); \
> +		if (err) { \
> +			data->sensors[idx].dev_attr.attr.name = NULL; \
> +			goto exit_remove; \
> +		} \
> +		idx++; \
> +		ro++; \
> +	} \
> +\
> +	/* Set up read-write sensors */ \
> +	rw = type##_rw_sensors; \
> +	while (rw->label) { \
> +		data->sensors[idx].dev_attr.attr.name = rw->label; \
> +		data->sensors[idx].dev_attr.attr.mode = S_IRUGO | S_IWUSR; \
> +		data->sensors[idx].dev_attr.show = rw->show; \
> +		data->sensors[idx].dev_attr.store = rw->set; \
> +		data->sensors[idx].index = rw->index; \
> +\
> +		err = device_create_file(&data->fw.pdev->dev, \
> +					 &data->sensors[idx].dev_attr); \
> +		if (err) { \
> +			data->sensors[idx].dev_attr.attr.name = NULL; \
> +			goto exit_remove; \
> +		} \
> +		idx++; \
> +		rw++; \
> +	} \
> +\
> +	err = device_create_file(&data->fw.pdev->dev, \
> +			&sensor_dev_attr_name.dev_attr); \
> +	if (err) \
> +		goto exit_remove; \
> +\
> +	return 0; \
> +\
> +exit_remove: \
> +	type##_remove_sensors(data); \
> +	return err; \
> +} 

It really shouldn't be necessary to have all of these macro functions. 
In this above macro, you would just have to pass the ro and rw 
structures along with a remove function pointer.  Since all of your 
types have common members, you could just have a common substructure and 
pass that around.

Regards,

Anthony Liguori
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ