Merge branch 'master' into for_paulus
[linux-drm-fsl-dcu.git] / drivers / ieee1394 / csr1212.c
index 61ddd5d37effab34520797ca6811ddafef5cfac1..c28f639823d238c187f31daca9552f88c6ec188b 100644 (file)
 #define __D (1 << CSR1212_KV_TYPE_DIRECTORY)
 #define __L (1 << CSR1212_KV_TYPE_LEAF)
 static const u_int8_t csr1212_key_id_type_map[0x30] = {
-       0,                      /* Reserved */
+       __C,                    /* used by Apple iSight */
        __D | __L,              /* Descriptor */
        __I | __D | __L,        /* Bus_Dependent_Info */
        __I | __D | __L,        /* Vendor */
        __I,                    /* Hardware_Version */
        0, 0,                   /* Reserved */
-       __D | __L,              /* Module */
-       0, 0, 0, 0,             /* Reserved */
+       __D | __L | __I,        /* Module */
+       __I, 0, 0, 0,           /* used by Apple iSight, Reserved */
        __I,                    /* Node_Capabilities */
        __L,                    /* EUI_64 */
        0, 0, 0,                /* Reserved */
@@ -779,7 +779,7 @@ static int csr1212_append_new_cache(struct csr1212_csr *csr, size_t romsize)
        romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
 
        csr_addr = csr->ops->allocate_addr_range(romsize, csr->max_rom, csr->private);
-       if (csr_addr == ~0ULL) {
+       if (csr_addr == CSR1212_INVALID_ADDR_SPACE) {
                return CSR1212_ENOMEM;
        }
        if (csr_addr < CSR1212_REGISTER_SPACE_BASE) {
@@ -1234,6 +1234,12 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
                                         csr->private);
                if (ret != CSR1212_SUCCESS)
                        return ret;
+
+               /* check ROM header's info_length */
+               if (i == 0 &&
+                   CSR1212_BE32_TO_CPU(csr->cache_head->data[0]) >> 24 !=
+                   bytes_to_quads(csr->bus_info_len) - 1)
+                       return CSR1212_EINVAL;
        }
 
        bi = (struct csr1212_bus_info_block_img*)csr->cache_head->data;
@@ -1250,9 +1256,6 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
                        return ret;
        }
 
-       if (bytes_to_quads(csr->bus_info_len - sizeof(csr1212_quad_t)) != bi->length)
-               return CSR1212_EINVAL;
-
 #if 0
        /* Apparently there are too many differnt wrong implementations of the
         * CRC algorithm that verifying them is moot. */
@@ -1261,7 +1264,7 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
                return CSR1212_EINVAL;
 #endif
 
-       cr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
+       cr = CSR1212_MALLOC(sizeof(*cr));
        if (!cr)
                return CSR1212_ENOMEM;
 
@@ -1393,8 +1396,7 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
        case CSR1212_KV_TYPE_LEAF:
                if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM) {
                        kv->value.leaf.data = CSR1212_MALLOC(quads_to_bytes(kvi_len));
-                       if (!kv->value.leaf.data)
-                       {
+                       if (!kv->value.leaf.data) {
                                ret = CSR1212_ENOMEM;
                                goto fail;
                        }
@@ -1462,7 +1464,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
                cache->next = NULL;
                csr->cache_tail = cache;
                cache->filled_head =
-                       CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
+                       CSR1212_MALLOC(sizeof(*cache->filled_head));
                if (!cache->filled_head) {
                        return CSR1212_ENOMEM;
                }
@@ -1484,7 +1486,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
        /* Now seach read portions of the cache to see if it is there. */
        for (cr = cache->filled_head; cr; cr = cr->next) {
                if (cache_index < cr->offset_start) {
-                       newcr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
+                       newcr = CSR1212_MALLOC(sizeof(*newcr));
                        if (!newcr)
                                return CSR1212_ENOMEM;
 
@@ -1508,7 +1510,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
 
        if (!cr) {
                cr = cache->filled_tail;
-               newcr = CSR1212_MALLOC(sizeof(struct csr1212_cache_region));
+               newcr = CSR1212_MALLOC(sizeof(*newcr));
                if (!newcr)
                        return CSR1212_ENOMEM;
 
@@ -1611,15 +1613,17 @@ int csr1212_parse_csr(struct csr1212_csr *csr)
        csr->root_kv->valid = 0;
        csr->root_kv->next = csr->root_kv;
        csr->root_kv->prev = csr->root_kv;
-       csr1212_get_keyval(csr, csr->root_kv);
+       ret = _csr1212_read_keyval(csr, csr->root_kv);
+       if (ret != CSR1212_SUCCESS)
+               return ret;
 
        /* Scan through the Root directory finding all extended ROM regions
         * and make cache regions for them */
        for (dentry = csr->root_kv->value.directory.dentries_head;
             dentry; dentry = dentry->next) {
-               if (dentry->kv->key.id == CSR1212_KV_ID_EXTENDED_ROM) {
-                       csr1212_get_keyval(csr, dentry->kv);
-
+               if (dentry->kv->key.id == CSR1212_KV_ID_EXTENDED_ROM &&
+                       !dentry->kv->valid) {
+                       ret = _csr1212_read_keyval(csr, dentry->kv);
                        if (ret != CSR1212_SUCCESS)
                                return ret;
                }