summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDorota Moskal <dorota.moskal@tieto.com>2012-09-27 13:22:18 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2012-10-09 23:48:07 +0200
commitd8f1b8e04a164749f22c00edf651f54e8b676ed8 (patch)
treef0286c2a0122d9a3171170a8bbfb1e10a2ca615b
parent03c0385dae8659c3cd90479409b8d32f520f75aa (diff)
downloadneard-d8f1b8e04a164749f22c00edf651f54e8b676ed8.tar.gz
neard-d8f1b8e04a164749f22c00edf651f54e8b676ed8.tar.bz2
neard-d8f1b8e04a164749f22c00edf651f54e8b676ed8.zip
nfctype1: Call write callback when writing failed
In some cases when writing was broken before allocating the cookie (e.g. when there was not enough space on tag) tag write callback wasn't called and writing was left 'in progress'.
-rw-r--r--plugins/nfctype1.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/plugins/nfctype1.c b/plugins/nfctype1.c
index 3506cf8..936bf89 100644
--- a/plugins/nfctype1.c
+++ b/plugins/nfctype1.c
@@ -553,7 +553,8 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx,
uid = near_tag_get_nfcid(adapter_idx, target_idx, &uid_length);
if (uid == NULL || uid_length != UID_LENGTH) {
near_error("Invalid type 1 UID");
- return -EINVAL;
+ err = -EINVAL;
+ goto out_err;
}
cmd.cmd = CMD_WRITE_E;
@@ -565,7 +566,7 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx,
if (cookie == NULL) {
g_free(uid);
err = -ENOMEM;
- return err;
+ goto out_err;
}
cookie->adapter_idx = adapter_idx;
@@ -581,6 +582,11 @@ static int data_write(uint32_t adapter_idx, uint32_t target_idx,
return near_adapter_send(cookie->adapter_idx, (uint8_t *) &cmd,
sizeof(cmd), data_write_resp, cookie,
t1_cookie_release);
+out_err:
+ if (cb != NULL)
+ cb(adapter_idx, target_idx, err);
+
+ return err;
}
/*
@@ -598,15 +604,20 @@ static int nfctype1_write(uint32_t adapter_idx, uint32_t target_idx,
near_tag_io_cb cb)
{
struct near_tag *tag;
+ int err;
DBG("");
- if (ndef == NULL || cb == NULL)
- return -EINVAL;
+ if (ndef == NULL || cb == NULL) {
+ err = -EINVAL;
+ goto out_err;
+ }
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
- return -EINVAL;
+ if (tag == NULL) {
+ err = -EINVAL;
+ goto out_err;
+ }
/* This check is valid for only static tags.
* Max data length on Type 1 Tag including TLV's
@@ -614,11 +625,23 @@ static int nfctype1_write(uint32_t adapter_idx, uint32_t target_idx,
if (near_tag_get_memory_layout(tag) == NEAR_TAG_MEMORY_STATIC) {
if ((ndef->length + 3) > TYPE1_STATIC_MAX_DATA_SIZE) {
near_error("not enough space on tag");
- return -ENOSPC;
+ err = -ENOSPC;
+ goto out_err;
}
}
return data_write(adapter_idx, target_idx, ndef, cb);
+
+ if (err < 0)
+ goto out_err;
+
+ return 0;
+
+out_err:
+ if (cb != NULL)
+ cb(adapter_idx, target_idx, err);
+
+ return err;
}
static int check_presence(uint8_t *resp, int length, void *data)