mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-20 11:13:58 +08:00
ieee1394: stricter error checks in csr1212
return -EINVAL becomes BUG_ON in checks of function call parameters. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
parent
982610bd0d
commit
64ff712321
@ -63,9 +63,9 @@ int hpsb_default_host_entry(struct hpsb_host *host)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = csr1212_associate_keyval(vend_id, text);
|
csr1212_associate_keyval(vend_id, text);
|
||||||
csr1212_release_keyval(text);
|
csr1212_release_keyval(text);
|
||||||
ret |= csr1212_attach_keyval_to_directory(root, vend_id);
|
ret = csr1212_attach_keyval_to_directory(root, vend_id);
|
||||||
csr1212_release_keyval(vend_id);
|
csr1212_release_keyval(vend_id);
|
||||||
if (ret != CSR1212_SUCCESS) {
|
if (ret != CSR1212_SUCCESS) {
|
||||||
csr1212_destroy_csr(host->csr.rom);
|
csr1212_destroy_csr(host->csr.rom);
|
||||||
@ -103,10 +103,12 @@ static int config_rom_ip1394_init(void)
|
|||||||
if (!ip1394_ud || !spec_id || !spec_desc || !ver || !ver_desc)
|
if (!ip1394_ud || !spec_id || !spec_desc || !ver || !ver_desc)
|
||||||
goto ip1394_fail;
|
goto ip1394_fail;
|
||||||
|
|
||||||
if (csr1212_associate_keyval(spec_id, spec_desc) == CSR1212_SUCCESS &&
|
csr1212_associate_keyval(spec_id, spec_desc);
|
||||||
csr1212_associate_keyval(ver, ver_desc) == CSR1212_SUCCESS &&
|
csr1212_associate_keyval(ver, ver_desc);
|
||||||
csr1212_attach_keyval_to_directory(ip1394_ud, spec_id) == CSR1212_SUCCESS &&
|
if (csr1212_attach_keyval_to_directory(ip1394_ud, spec_id)
|
||||||
csr1212_attach_keyval_to_directory(ip1394_ud, ver) == CSR1212_SUCCESS)
|
== CSR1212_SUCCESS &&
|
||||||
|
csr1212_attach_keyval_to_directory(ip1394_ud, ver)
|
||||||
|
== CSR1212_SUCCESS)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
ip1394_fail:
|
ip1394_fail:
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
|
#include <asm/bug.h>
|
||||||
#include <asm/byteorder.h>
|
#include <asm/byteorder.h>
|
||||||
|
|
||||||
#include "csr1212.h"
|
#include "csr1212.h"
|
||||||
@ -305,43 +306,29 @@ struct csr1212_keyval *csr1212_new_directory(u8 key)
|
|||||||
return kv;
|
return kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int csr1212_associate_keyval(struct csr1212_keyval *kv,
|
void csr1212_associate_keyval(struct csr1212_keyval *kv,
|
||||||
struct csr1212_keyval *associate)
|
struct csr1212_keyval *associate)
|
||||||
{
|
{
|
||||||
if (!kv || !associate)
|
BUG_ON(!kv || !associate || kv->key.id == CSR1212_KV_ID_DESCRIPTOR ||
|
||||||
return -EINVAL;
|
(associate->key.id != CSR1212_KV_ID_DESCRIPTOR &&
|
||||||
|
associate->key.id != CSR1212_KV_ID_DEPENDENT_INFO &&
|
||||||
if (kv->key.id == CSR1212_KV_ID_DESCRIPTOR ||
|
associate->key.id != CSR1212_KV_ID_EXTENDED_KEY &&
|
||||||
(associate->key.id != CSR1212_KV_ID_DESCRIPTOR &&
|
associate->key.id != CSR1212_KV_ID_EXTENDED_DATA &&
|
||||||
associate->key.id != CSR1212_KV_ID_DEPENDENT_INFO &&
|
associate->key.id < 0x30) ||
|
||||||
associate->key.id != CSR1212_KV_ID_EXTENDED_KEY &&
|
(kv->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID &&
|
||||||
associate->key.id != CSR1212_KV_ID_EXTENDED_DATA &&
|
associate->key.id != CSR1212_KV_ID_EXTENDED_KEY) ||
|
||||||
associate->key.id < 0x30))
|
(kv->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
|
||||||
return -EINVAL;
|
associate->key.id != CSR1212_KV_ID_EXTENDED_DATA) ||
|
||||||
|
(associate->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
|
||||||
if (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID &&
|
kv->key.id != CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID) ||
|
||||||
associate->key.id != CSR1212_KV_ID_EXTENDED_KEY)
|
(associate->key.id == CSR1212_KV_ID_EXTENDED_DATA &&
|
||||||
return -EINVAL;
|
kv->key.id != CSR1212_KV_ID_EXTENDED_KEY));
|
||||||
|
|
||||||
if (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
|
|
||||||
associate->key.id != CSR1212_KV_ID_EXTENDED_DATA)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (associate->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
|
|
||||||
kv->key.id != CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (associate->key.id == CSR1212_KV_ID_EXTENDED_DATA &&
|
|
||||||
kv->key.id != CSR1212_KV_ID_EXTENDED_KEY)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (kv->associate)
|
if (kv->associate)
|
||||||
csr1212_release_keyval(kv->associate);
|
csr1212_release_keyval(kv->associate);
|
||||||
|
|
||||||
associate->refcnt++;
|
associate->refcnt++;
|
||||||
kv->associate = associate;
|
kv->associate = associate;
|
||||||
|
|
||||||
return CSR1212_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
|
int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
|
||||||
@ -349,8 +336,7 @@ int csr1212_attach_keyval_to_directory(struct csr1212_keyval *dir,
|
|||||||
{
|
{
|
||||||
struct csr1212_dentry *dentry;
|
struct csr1212_dentry *dentry;
|
||||||
|
|
||||||
if (!kv || !dir || dir->key.type != CSR1212_KV_TYPE_DIRECTORY)
|
BUG_ON(!kv || !dir || dir->key.type != CSR1212_KV_TYPE_DIRECTORY);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
dentry = CSR1212_MALLOC(sizeof(*dentry));
|
dentry = CSR1212_MALLOC(sizeof(*dentry));
|
||||||
if (!dentry)
|
if (!dentry)
|
||||||
@ -611,9 +597,8 @@ static int csr1212_append_new_cache(struct csr1212_csr *csr, size_t romsize)
|
|||||||
struct csr1212_csr_rom_cache *cache;
|
struct csr1212_csr_rom_cache *cache;
|
||||||
u64 csr_addr;
|
u64 csr_addr;
|
||||||
|
|
||||||
if (!csr || !csr->ops || !csr->ops->allocate_addr_range ||
|
BUG_ON(!csr || !csr->ops || !csr->ops->allocate_addr_range ||
|
||||||
!csr->ops->release_addr || csr->max_rom < 1)
|
!csr->ops->release_addr || csr->max_rom < 1);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* ROM size must be a multiple of csr->max_rom */
|
/* ROM size must be a multiple of csr->max_rom */
|
||||||
romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
|
romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
|
||||||
@ -950,8 +935,7 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
|
|||||||
int ret;
|
int ret;
|
||||||
int init_offset;
|
int init_offset;
|
||||||
|
|
||||||
if (!csr)
|
BUG_ON(!csr);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
cache = csr->cache_head;
|
cache = csr->cache_head;
|
||||||
|
|
||||||
@ -1011,8 +995,7 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
|
|||||||
|
|
||||||
/* Make sure the Extended ROM leaf is a multiple of
|
/* Make sure the Extended ROM leaf is a multiple of
|
||||||
* max_rom in size. */
|
* max_rom in size. */
|
||||||
if (csr->max_rom < 1)
|
BUG_ON(csr->max_rom < 1);
|
||||||
return -EINVAL;
|
|
||||||
leaf_size = (cache->len + (csr->max_rom - 1)) &
|
leaf_size = (cache->len + (csr->max_rom - 1)) &
|
||||||
~(csr->max_rom - 1);
|
~(csr->max_rom - 1);
|
||||||
|
|
||||||
@ -1278,8 +1261,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
|
|||||||
u32 *cache_ptr;
|
u32 *cache_ptr;
|
||||||
u16 kv_len = 0;
|
u16 kv_len = 0;
|
||||||
|
|
||||||
if (!csr || !kv || csr->max_rom < 1)
|
BUG_ON(!csr || !kv || csr->max_rom < 1);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* First find which cache the data should be in (or go in if not read
|
/* First find which cache the data should be in (or go in if not read
|
||||||
* yet). */
|
* yet). */
|
||||||
@ -1436,8 +1418,7 @@ int csr1212_parse_csr(struct csr1212_csr *csr)
|
|||||||
struct csr1212_dentry *dentry;
|
struct csr1212_dentry *dentry;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!csr || !csr->ops || !csr->ops->bus_read)
|
BUG_ON(!csr || !csr->ops || !csr->ops->bus_read);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
ret = csr1212_parse_bus_info_block(csr);
|
ret = csr1212_parse_bus_info_block(csr);
|
||||||
if (ret != CSR1212_SUCCESS)
|
if (ret != CSR1212_SUCCESS)
|
||||||
|
@ -283,8 +283,8 @@ extern struct csr1212_keyval *csr1212_new_string_descriptor_leaf(const char *s);
|
|||||||
* Take care with subsequent ROM modifications: There is no function to remove
|
* Take care with subsequent ROM modifications: There is no function to remove
|
||||||
* previously specified associations.
|
* previously specified associations.
|
||||||
*/
|
*/
|
||||||
extern int csr1212_associate_keyval(struct csr1212_keyval *kv,
|
extern void csr1212_associate_keyval(struct csr1212_keyval *kv,
|
||||||
struct csr1212_keyval *associate);
|
struct csr1212_keyval *associate);
|
||||||
|
|
||||||
|
|
||||||
/* The following functions manage the association of a keyval and directories.
|
/* The following functions manage the association of a keyval and directories.
|
||||||
|
Loading…
Reference in New Issue
Block a user