summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
a27837d)
This is preparation for when we will track the context in am7xxx_device
as well, and as a side effect those functions now look more consistent
with the other ones.
-static am7xxx_device *add_new_device(am7xxx_device **devices_list)
+static am7xxx_device *add_new_device(am7xxx_context *ctx)
+ am7xxx_device **devices_list;
am7xxx_device *new_device;
am7xxx_device *new_device;
+ if (ctx == NULL) {
+ fprintf(stderr, "%s: context must not be NULL!\n", __func__);
+ return NULL;
+ }
+
+ devices_list = &(ctx->devices_list);
+
new_device = malloc(sizeof(*new_device));
if (new_device == NULL) {
perror("malloc");
new_device = malloc(sizeof(*new_device));
if (new_device == NULL) {
perror("malloc");
-static am7xxx_device *find_device(am7xxx_device *devices_list,
+static am7xxx_device *find_device(am7xxx_context *ctx,
unsigned int device_index)
{
unsigned int i = 0;
unsigned int device_index)
{
unsigned int i = 0;
- am7xxx_device *current = devices_list;
+ am7xxx_device *current;
+ if (ctx == NULL) {
+ fprintf(stderr, "%s: context must not be NULL!\n", __func__);
+ return NULL;
+ }
+
+ current = ctx->devices_list;
while (current && i++ < device_index)
current = current->next;
while (current && i++ < device_index)
current = current->next;
printf("am7xxx device found, index: %d, name: %s\n",
current_index,
supported_devices[j].name);
printf("am7xxx device found, index: %d, name: %s\n",
current_index,
supported_devices[j].name);
- new_device = add_new_device(&(ctx->devices_list));
+ new_device = add_new_device(ctx);
if (new_device == NULL) {
/* XXX, the caller may want
* to call am7xxx_shutdown() if
if (new_device == NULL) {
/* XXX, the caller may want
* to call am7xxx_shutdown() if
} else if (op == SCAN_OP_OPEN_DEVICE &&
current_index == open_device_index) {
} else if (op == SCAN_OP_OPEN_DEVICE &&
current_index == open_device_index) {
- *dev = find_device(ctx->devices_list, open_device_index);
+ *dev = find_device(ctx, open_device_index);
if (*dev == NULL) {
ret = -ENODEV;
goto out;
if (*dev == NULL) {
ret = -ENODEV;
goto out;