From bdc58e3bef647b39145ebc951bb4b1904e239212 Mon Sep 17 00:00:00 2001 From: simran singhal Date: Wed, 22 Feb 2017 14:40:15 +0530 Subject: staging: most: Using macro DIV_ROUND_UP The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)). It clarifies the divisor calculations. This occurence was detected using the coccinelle script: @@ expression e1; expression e2; @@ ( - ((e1) + e2 - 1) / (e2) + DIV_ROUND_UP(e1,e2) | - ((e1) + (e2 - 1)) / (e2) + DIV_ROUND_UP(e1,e2) ) Signed-off-by: simran singhal Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/hdm-dim2/dim2_hal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/hdm-dim2/dim2_hal.c b/drivers/staging/most/hdm-dim2/dim2_hal.c index 0b9816ce1761..d604ec09df28 100644 --- a/drivers/staging/most/hdm-dim2/dim2_hal.c +++ b/drivers/staging/most/hdm-dim2/dim2_hal.c @@ -18,6 +18,7 @@ #include "dim2_errors.h" #include "dim2_reg.h" #include +#include /* * Size factor for isochronous DBR buffer. @@ -49,7 +50,7 @@ #define DBR_SIZE (16 * 1024) /* specified by IP */ #define DBR_BLOCK_SIZE (DBR_SIZE / 32 / DBR_MAP_SIZE) -#define ROUND_UP_TO(x, d) (((x) + (d) - 1) / (d) * (d)) +#define ROUND_UP_TO(x, d) (DIV_ROUND_UP(x, (d)) * (d)) /* -------------------------------------------------------------------------- */ /* generic helper functions and macros */ @@ -117,7 +118,7 @@ static int alloc_dbr(u16 size) return DBR_SIZE; /* out of memory */ for (i = 0; i < DBR_MAP_SIZE; i++) { - u32 const blocks = (size + DBR_BLOCK_SIZE - 1) / DBR_BLOCK_SIZE; + u32 const blocks = DIV_ROUND_UP(size, DBR_BLOCK_SIZE); u32 mask = ~((~(u32)0) << blocks); do { @@ -137,7 +138,7 @@ static int alloc_dbr(u16 size) static void free_dbr(int offs, int size) { int block_idx = offs / DBR_BLOCK_SIZE; - u32 const blocks = (size + DBR_BLOCK_SIZE - 1) / DBR_BLOCK_SIZE; + u32 const blocks = DIV_ROUND_UP(size, DBR_BLOCK_SIZE); u32 mask = ~((~(u32)0) << blocks); mask <<= block_idx % 32; -- cgit v1.2.3 From 0b4194fd09530c0f22783882cb3fb5b272a448c1 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:30 +0200 Subject: staging: most: fix comment of the function add_link_store This patch replaces the name store_add_link by the add_link_store in the comment for the corresponding function. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 191404bc5906..a4beb32a8bbf 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -943,7 +943,7 @@ most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch) } /** - * store_add_link - store() function for add_link attribute + * add_link_store - store() function for add_link attribute * @aim_obj: pointer to AIM object * @attr: its attributes * @buf: buffer -- cgit v1.2.3 From bf676f4ce2550de749d5c09524761610c91514a6 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:31 +0200 Subject: staging: most: fix comment of the function remove_link_store This patch replaces the name store_remove_link by the remove_link_store in the comment for the corresponding function. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index a4beb32a8bbf..fb5e8f2ecb74 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -1017,7 +1017,7 @@ static struct most_aim_attribute most_aim_attr_add_link = __ATTR_RW(add_link); /** - * store_remove_link - store function for remove_link attribute + * remove_link_store - store function for remove_link attribute * @aim_obj: pointer to AIM object * @attr: its attributes * @buf: buffer -- cgit v1.2.3 From 4dd7c7c7b3671b1939d18ff7cc872f12187f9e15 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Fri, 7 Apr 2017 15:38:32 +0200 Subject: staging: most: core: fix function names This patch fixes the names of the show/store functions to match the naming convention. Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 68 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 36 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index fb5e8f2ecb74..affb50043153 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -256,7 +256,7 @@ static void most_channel_release(struct kobject *kobj) kfree(c); } -static ssize_t show_available_directions(struct most_c_obj *c, +static ssize_t available_directions_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { @@ -271,7 +271,7 @@ static ssize_t show_available_directions(struct most_c_obj *c, return strlen(buf); } -static ssize_t show_available_datatypes(struct most_c_obj *c, +static ssize_t available_datatypes_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { @@ -290,10 +290,9 @@ static ssize_t show_available_datatypes(struct most_c_obj *c, return strlen(buf); } -static -ssize_t show_number_of_packet_buffers(struct most_c_obj *c, - struct most_c_attr *attr, - char *buf) +static ssize_t number_of_packet_buffers_show(struct most_c_obj *c, + struct most_c_attr *attr, + char *buf) { unsigned int i = c->channel_id; @@ -301,10 +300,9 @@ ssize_t show_number_of_packet_buffers(struct most_c_obj *c, c->iface->channel_vector[i].num_buffers_packet); } -static -ssize_t show_number_of_stream_buffers(struct most_c_obj *c, - struct most_c_attr *attr, - char *buf) +static ssize_t number_of_stream_buffers_show(struct most_c_obj *c, + struct most_c_attr *attr, + char *buf) { unsigned int i = c->channel_id; @@ -312,10 +310,9 @@ ssize_t show_number_of_stream_buffers(struct most_c_obj *c, c->iface->channel_vector[i].num_buffers_streaming); } -static -ssize_t show_size_of_packet_buffer(struct most_c_obj *c, - struct most_c_attr *attr, - char *buf) +static ssize_t size_of_packet_buffer_show(struct most_c_obj *c, + struct most_c_attr *attr, + char *buf) { unsigned int i = c->channel_id; @@ -323,10 +320,9 @@ ssize_t show_size_of_packet_buffer(struct most_c_obj *c, c->iface->channel_vector[i].buffer_size_packet); } -static -ssize_t show_size_of_stream_buffer(struct most_c_obj *c, - struct most_c_attr *attr, - char *buf) +static ssize_t size_of_stream_buffer_show(struct most_c_obj *c, + struct most_c_attr *attr, + char *buf) { unsigned int i = c->channel_id; @@ -334,7 +330,7 @@ ssize_t show_size_of_stream_buffer(struct most_c_obj *c, c->iface->channel_vector[i].buffer_size_streaming); } -static ssize_t show_channel_starving(struct most_c_obj *c, +static ssize_t channel_starving_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { @@ -342,7 +338,7 @@ static ssize_t show_channel_starving(struct most_c_obj *c, } #define create_show_channel_attribute(val) \ - static MOST_CHNL_ATTR(val, 0444, show_##val, NULL) + static MOST_CHNL_ATTR(val, 0444, val##_show, NULL) create_show_channel_attribute(available_directions); create_show_channel_attribute(available_datatypes); @@ -352,14 +348,14 @@ create_show_channel_attribute(size_of_stream_buffer); create_show_channel_attribute(size_of_packet_buffer); create_show_channel_attribute(channel_starving); -static ssize_t show_set_number_of_buffers(struct most_c_obj *c, +static ssize_t set_number_of_buffers_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers); } -static ssize_t store_set_number_of_buffers(struct most_c_obj *c, +static ssize_t set_number_of_buffers_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -371,14 +367,14 @@ static ssize_t store_set_number_of_buffers(struct most_c_obj *c, return count; } -static ssize_t show_set_buffer_size(struct most_c_obj *c, +static ssize_t set_buffer_size_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size); } -static ssize_t store_set_buffer_size(struct most_c_obj *c, +static ssize_t set_buffer_size_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -390,7 +386,7 @@ static ssize_t store_set_buffer_size(struct most_c_obj *c, return count; } -static ssize_t show_set_direction(struct most_c_obj *c, +static ssize_t set_direction_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { @@ -401,7 +397,7 @@ static ssize_t show_set_direction(struct most_c_obj *c, return snprintf(buf, PAGE_SIZE, "unconfigured\n"); } -static ssize_t store_set_direction(struct most_c_obj *c, +static ssize_t set_direction_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -421,7 +417,7 @@ static ssize_t store_set_direction(struct most_c_obj *c, return count; } -static ssize_t show_set_datatype(struct most_c_obj *c, +static ssize_t set_datatype_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { @@ -434,7 +430,7 @@ static ssize_t show_set_datatype(struct most_c_obj *c, return snprintf(buf, PAGE_SIZE, "unconfigured\n"); } -static ssize_t store_set_datatype(struct most_c_obj *c, +static ssize_t set_datatype_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -455,14 +451,14 @@ static ssize_t store_set_datatype(struct most_c_obj *c, return count; } -static ssize_t show_set_subbuffer_size(struct most_c_obj *c, +static ssize_t set_subbuffer_size_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size); } -static ssize_t store_set_subbuffer_size(struct most_c_obj *c, +static ssize_t set_subbuffer_size_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -474,14 +470,14 @@ static ssize_t store_set_subbuffer_size(struct most_c_obj *c, return count; } -static ssize_t show_set_packets_per_xact(struct most_c_obj *c, +static ssize_t set_packets_per_xact_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact); } -static ssize_t store_set_packets_per_xact(struct most_c_obj *c, +static ssize_t set_packets_per_xact_store(struct most_c_obj *c, struct most_c_attr *attr, const char *buf, size_t count) @@ -494,7 +490,7 @@ static ssize_t store_set_packets_per_xact(struct most_c_obj *c, } #define create_channel_attribute(value) \ - static MOST_CHNL_ATTR(value, 0644, show_##value, store_##value) + static MOST_CHNL_ATTR(value, 0644, value##_show, value##_store) create_channel_attribute(set_buffer_size); create_channel_attribute(set_number_of_buffers); @@ -652,7 +648,7 @@ static void most_inst_release(struct kobject *kobj) kfree(inst); } -static ssize_t show_description(struct most_inst_obj *instance_obj, +static ssize_t description_show(struct most_inst_obj *instance_obj, struct most_inst_attribute *attr, char *buf) { @@ -660,7 +656,7 @@ static ssize_t show_description(struct most_inst_obj *instance_obj, instance_obj->iface->description); } -static ssize_t show_interface(struct most_inst_obj *instance_obj, +static ssize_t interface_show(struct most_inst_obj *instance_obj, struct most_inst_attribute *attr, char *buf) { @@ -688,7 +684,7 @@ static ssize_t show_interface(struct most_inst_obj *instance_obj, } #define create_inst_attribute(value) \ - static MOST_INST_ATTR(value, 0444, show_##value, NULL) + static MOST_INST_ATTR(value, 0444, value##_show, NULL) create_inst_attribute(description); create_inst_attribute(interface); -- cgit v1.2.3 From 1c74e3ab95dab9caec3a30e8de9ac2e41f967e38 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Fri, 7 Apr 2017 15:38:33 +0200 Subject: staging: most: core: make use of __ATTR_* macros This patch replaces the proprietary macros with those provided by the kernel. Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index affb50043153..9cbd893989b3 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -127,10 +127,6 @@ struct most_c_attr { #define to_channel_attr(a) container_of(a, struct most_c_attr, attr) -#define MOST_CHNL_ATTR(_name, _mode, _show, _store) \ - struct most_c_attr most_chnl_attr_##_name = \ - __ATTR(_name, _mode, _show, _store) - /** * channel_attr_show - show function of channel object * @kobj: pointer to its kobject @@ -338,7 +334,7 @@ static ssize_t channel_starving_show(struct most_c_obj *c, } #define create_show_channel_attribute(val) \ - static MOST_CHNL_ATTR(val, 0444, val##_show, NULL) + static struct most_c_attr most_chnl_attr_##val = __ATTR_RO(val) create_show_channel_attribute(available_directions); create_show_channel_attribute(available_datatypes); @@ -490,7 +486,7 @@ static ssize_t set_packets_per_xact_store(struct most_c_obj *c, } #define create_channel_attribute(value) \ - static MOST_CHNL_ATTR(value, 0644, value##_show, value##_store) + static struct most_c_attr most_chnl_attr_##value = __ATTR_RW(value) create_channel_attribute(set_buffer_size); create_channel_attribute(set_number_of_buffers); @@ -558,9 +554,6 @@ create_most_c_obj(const char *name, struct kobject *parent) /* ___ ___ * ___I N S T A N C E___ */ -#define MOST_INST_ATTR(_name, _mode, _show, _store) \ - struct most_inst_attribute most_inst_attr_##_name = \ - __ATTR(_name, _mode, _show, _store) static struct list_head instance_list; @@ -683,11 +676,11 @@ static ssize_t interface_show(struct most_inst_obj *instance_obj, return snprintf(buf, PAGE_SIZE, "unknown\n"); } -#define create_inst_attribute(value) \ - static MOST_INST_ATTR(value, 0444, value##_show, NULL) +static struct most_inst_attribute most_inst_attr_description = + __ATTR_RO(description); -create_inst_attribute(description); -create_inst_attribute(interface); +static struct most_inst_attribute most_inst_attr_interface = + __ATTR_RO(interface); static struct attribute *most_inst_def_attrs[] = { &most_inst_attr_description.attr, -- cgit v1.2.3 From 7dc70220e92fc045ab2357874a67f06a916e0b41 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:34 +0200 Subject: staging: most: core: consolidate channel attributes This patch replaces 13 temporary variables representing the attributes to control the channel with an array of 13 elements to keep the corresponding code compact. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 61 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 9cbd893989b3..720b9ced1a9d 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -333,17 +333,6 @@ static ssize_t channel_starving_show(struct most_c_obj *c, return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving); } -#define create_show_channel_attribute(val) \ - static struct most_c_attr most_chnl_attr_##val = __ATTR_RO(val) - -create_show_channel_attribute(available_directions); -create_show_channel_attribute(available_datatypes); -create_show_channel_attribute(number_of_packet_buffers); -create_show_channel_attribute(number_of_stream_buffers); -create_show_channel_attribute(size_of_stream_buffer); -create_show_channel_attribute(size_of_packet_buffer); -create_show_channel_attribute(channel_starving); - static ssize_t set_number_of_buffers_show(struct most_c_obj *c, struct most_c_attr *attr, char *buf) @@ -485,33 +474,39 @@ static ssize_t set_packets_per_xact_store(struct most_c_obj *c, return count; } -#define create_channel_attribute(value) \ - static struct most_c_attr most_chnl_attr_##value = __ATTR_RW(value) - -create_channel_attribute(set_buffer_size); -create_channel_attribute(set_number_of_buffers); -create_channel_attribute(set_direction); -create_channel_attribute(set_datatype); -create_channel_attribute(set_subbuffer_size); -create_channel_attribute(set_packets_per_xact); +static struct most_c_attr most_c_attrs[] = { + __ATTR_RO(available_directions), + __ATTR_RO(available_datatypes), + __ATTR_RO(number_of_packet_buffers), + __ATTR_RO(number_of_stream_buffers), + __ATTR_RO(size_of_stream_buffer), + __ATTR_RO(size_of_packet_buffer), + __ATTR_RO(channel_starving), + __ATTR_RW(set_buffer_size), + __ATTR_RW(set_number_of_buffers), + __ATTR_RW(set_direction), + __ATTR_RW(set_datatype), + __ATTR_RW(set_subbuffer_size), + __ATTR_RW(set_packets_per_xact), +}; /** * most_channel_def_attrs - array of default attributes of channel object */ static struct attribute *most_channel_def_attrs[] = { - &most_chnl_attr_available_directions.attr, - &most_chnl_attr_available_datatypes.attr, - &most_chnl_attr_number_of_packet_buffers.attr, - &most_chnl_attr_number_of_stream_buffers.attr, - &most_chnl_attr_size_of_packet_buffer.attr, - &most_chnl_attr_size_of_stream_buffer.attr, - &most_chnl_attr_set_number_of_buffers.attr, - &most_chnl_attr_set_buffer_size.attr, - &most_chnl_attr_set_direction.attr, - &most_chnl_attr_set_datatype.attr, - &most_chnl_attr_set_subbuffer_size.attr, - &most_chnl_attr_set_packets_per_xact.attr, - &most_chnl_attr_channel_starving.attr, + &most_c_attrs[0].attr, + &most_c_attrs[1].attr, + &most_c_attrs[2].attr, + &most_c_attrs[3].attr, + &most_c_attrs[4].attr, + &most_c_attrs[5].attr, + &most_c_attrs[6].attr, + &most_c_attrs[7].attr, + &most_c_attrs[8].attr, + &most_c_attrs[9].attr, + &most_c_attrs[10].attr, + &most_c_attrs[11].attr, + &most_c_attrs[12].attr, NULL, }; -- cgit v1.2.3 From add98da7da79f38fd22d8852ed1066952d8b02aa Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:35 +0200 Subject: staging: most: core: separate property showing links Currently an AIM has the following properties available to manage links: - write-only "remove_link" used to remove a link from a list - read/write "add_link" used to add a link to a list and display them This patch transfers the read functionality of "add_link" to the new read-only property "links" to build consistent set of properties to control the list of links. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 720b9ced1a9d..7fc7cb39ea2b 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -831,9 +831,9 @@ static void most_aim_release(struct kobject *kobj) kfree(aim_obj); } -static ssize_t add_link_show(struct most_aim_obj *aim_obj, - struct most_aim_attribute *attr, - char *buf) +static ssize_t links_show(struct most_aim_obj *aim_obj, + struct most_aim_attribute *attr, + char *buf) { struct most_c_obj *c; struct most_inst_obj *i; @@ -854,6 +854,9 @@ static ssize_t add_link_show(struct most_aim_obj *aim_obj, return offs; } +static struct most_aim_attribute most_aim_attr_links = + __ATTR_RO(links); + /** * split_string - parses and changes string in the buffer buf and * splits it into two mandatory and one optional substrings. @@ -998,7 +1001,7 @@ static ssize_t add_link_store(struct most_aim_obj *aim_obj, } static struct most_aim_attribute most_aim_attr_add_link = - __ATTR_RW(add_link); + __ATTR_WO(add_link); /** * remove_link_store - store function for remove_link attribute @@ -1044,6 +1047,7 @@ static struct most_aim_attribute most_aim_attr_remove_link = __ATTR_WO(remove_link); static struct attribute *most_aim_def_attrs[] = { + &most_aim_attr_links.attr, &most_aim_attr_add_link.attr, &most_aim_attr_remove_link.attr, NULL, -- cgit v1.2.3 From 5f788625cd4c5d4062fc3f95308de74d65d7a314 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:36 +0200 Subject: staging: most: consolidate attributes for list of links This patch replaces three temporary variables representing the attributes to control the links between the AIMs and HDMs with an array of three elements to keep the corresponding code compact. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/mostcore/core.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/mostcore/core.c b/drivers/staging/most/mostcore/core.c index 7fc7cb39ea2b..675b2a9e66c1 100644 --- a/drivers/staging/most/mostcore/core.c +++ b/drivers/staging/most/mostcore/core.c @@ -854,9 +854,6 @@ static ssize_t links_show(struct most_aim_obj *aim_obj, return offs; } -static struct most_aim_attribute most_aim_attr_links = - __ATTR_RO(links); - /** * split_string - parses and changes string in the buffer buf and * splits it into two mandatory and one optional substrings. @@ -1000,9 +997,6 @@ static ssize_t add_link_store(struct most_aim_obj *aim_obj, return len; } -static struct most_aim_attribute most_aim_attr_add_link = - __ATTR_WO(add_link); - /** * remove_link_store - store function for remove_link attribute * @aim_obj: pointer to AIM object @@ -1043,13 +1037,16 @@ static ssize_t remove_link_store(struct most_aim_obj *aim_obj, return len; } -static struct most_aim_attribute most_aim_attr_remove_link = - __ATTR_WO(remove_link); +static struct most_aim_attribute most_aim_attrs[] = { + __ATTR_RO(links), + __ATTR_WO(add_link), + __ATTR_WO(remove_link), +}; static struct attribute *most_aim_def_attrs[] = { - &most_aim_attr_links.attr, - &most_aim_attr_add_link.attr, - &most_aim_attr_remove_link.attr, + &most_aim_attrs[0].attr, + &most_aim_attrs[1].attr, + &most_aim_attrs[2].attr, NULL, }; -- cgit v1.2.3 From 2c4aaa1fffe8d01c621e2515cd5f290227949e71 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:37 +0200 Subject: staging: most: destroy cdev when channel gets disconnected When a channel is being removed while an application holds the corresponding character device, this device is going to be destroyed only after the application closes the file descriptor and releases character device. In case the channel appears again before the application closes the file descriptor it holds, the channel cannot be linked. This patch changes the described behavior and destroys the character device at the time the channel get disconnected from the AIM. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/aim-cdev/cdev.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/aim-cdev/cdev.c b/drivers/staging/most/aim-cdev/cdev.c index 7f51024dc5eb..1e5cbc893496 100644 --- a/drivers/staging/most/aim-cdev/cdev.c +++ b/drivers/staging/most/aim-cdev/cdev.c @@ -99,11 +99,16 @@ static void destroy_cdev(struct aim_channel *c) device_destroy(aim_class, c->devno); cdev_del(&c->cdev); - kfifo_free(&c->fifo); spin_lock_irqsave(&ch_list_lock, flags); list_del(&c->list); spin_unlock_irqrestore(&ch_list_lock, flags); +} + +static void destroy_channel(struct aim_channel *c) +{ ida_simple_remove(&minor_id, MINOR(c->devno)); + kfifo_free(&c->fifo); + kfree(c); } /** @@ -170,9 +175,8 @@ static int aim_close(struct inode *inode, struct file *filp) stop_channel(c); mutex_unlock(&c->io_mutex); } else { - destroy_cdev(c); mutex_unlock(&c->io_mutex); - kfree(c); + destroy_channel(c); } return 0; } @@ -337,14 +341,14 @@ static int aim_disconnect_channel(struct most_interface *iface, int channel_id) spin_lock(&c->unlink); c->dev = NULL; spin_unlock(&c->unlink); + destroy_cdev(c); if (c->access_ref) { stop_channel(c); wake_up_interruptible(&c->wq); mutex_unlock(&c->io_mutex); } else { - destroy_cdev(c); mutex_unlock(&c->io_mutex); - kfree(c); + destroy_channel(c); } return 0; } @@ -546,7 +550,7 @@ static void __exit mod_exit(void) list_for_each_entry_safe(c, tmp, &channel_list, list) { destroy_cdev(c); - kfree(c); + destroy_channel(c); } class_destroy(aim_class); unregister_chrdev_region(aim_devno, 1); -- cgit v1.2.3 From f500192890c7c6745a92b677f5f69e58a2d60715 Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:38 +0200 Subject: staging: most: usb: fix calculation of the extra_len The final size of the buffer used for the streaming transfer consists of the size for the user payload (buffer_size) and the size for the gaps needed by the controller (extra_len). The current implementation of the hdm_configure_channel() corrects the buffer size down to the next appropriate for the hardware value, that is the whole number of frames, but uses the old unaligned value to calculate the extra_len. Current patch fixes the described problem. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/hdm-usb/hdm_usb.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c index 65211d1824b7..6e94ee2b4fb3 100644 --- a/drivers/staging/most/hdm-usb/hdm_usb.c +++ b/drivers/staging/most/hdm-usb/hdm_usb.c @@ -649,8 +649,6 @@ static int hdm_configure_channel(struct most_interface *iface, int channel, { unsigned int num_frames; unsigned int frame_size; - unsigned int temp_size; - unsigned int tail_space; struct most_dev *mdev = to_mdev(iface); struct device *dev = &mdev->usb_device->dev; @@ -685,7 +683,6 @@ static int hdm_configure_channel(struct most_interface *iface, int channel, } mdev->padding_active[channel] = true; - temp_size = conf->buffer_size; frame_size = get_stream_frame_size(conf); if (frame_size == 0 || frame_size > USB_MTU) { @@ -693,25 +690,19 @@ static int hdm_configure_channel(struct most_interface *iface, int channel, return -EINVAL; } + num_frames = conf->buffer_size / frame_size; + if (conf->buffer_size % frame_size) { - u16 tmp_val; - - tmp_val = conf->buffer_size / frame_size; - conf->buffer_size = tmp_val * frame_size; - dev_notice(dev, - "Channel %d - rounding buffer size to %d bytes, channel config says %d bytes\n", - channel, - conf->buffer_size, - temp_size); - } + u16 old_size = conf->buffer_size; - num_frames = conf->buffer_size / frame_size; - tail_space = num_frames * (USB_MTU - frame_size); - temp_size += tail_space; + conf->buffer_size = num_frames * frame_size; + dev_warn(dev, "%s: fixed buffer size (%d -> %d)\n", + mdev->suffix[channel], old_size, conf->buffer_size); + } /* calculate extra length to comply w/ HW padding */ - conf->extra_len = (DIV_ROUND_UP(temp_size, USB_MTU) * USB_MTU) - - conf->buffer_size; + conf->extra_len = num_frames * (USB_MTU - frame_size); + exit: mdev->conf[channel] = *conf; if (conf->data_type == MOST_CH_ASYNC) { -- cgit v1.2.3 From 5c13155d190464fade0344e16b6341f18af25f1f Mon Sep 17 00:00:00 2001 From: Andrey Shvetsov Date: Fri, 7 Apr 2017 15:38:39 +0200 Subject: staging: most: usb: fix size overflow Despite the user payload may not be bigger than (2**16 - 1) bytes, the final packet size may be bigger because of the gap space needed for the controller. This patch removes the temporary variables of the type u16 that are used to hold the offsets that may be bigger than 2**16 bytes. Signed-off-by: Andrey Shvetsov Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/hdm-usb/hdm_usb.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c index 6e94ee2b4fb3..ad907e9c59bb 100644 --- a/drivers/staging/most/hdm-usb/hdm_usb.c +++ b/drivers/staging/most/hdm-usb/hdm_usb.c @@ -281,7 +281,6 @@ static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo) struct most_channel_config *conf = &mdev->conf[channel]; unsigned int frame_size = get_stream_frame_size(conf); unsigned int j, num_frames; - u16 rd_addr, wr_addr; if (!frame_size) return -EIO; @@ -293,13 +292,10 @@ static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo) return -EIO; } - for (j = 1; j < num_frames; j++) { - wr_addr = (num_frames - j) * USB_MTU; - rd_addr = (num_frames - j) * frame_size; - memmove(mbo->virt_address + wr_addr, - mbo->virt_address + rd_addr, + for (j = num_frames - 1; j > 0; j--) + memmove(mbo->virt_address + j * USB_MTU, + mbo->virt_address + j * frame_size, frame_size); - } mbo->buffer_length = num_frames * USB_MTU; return 0; } -- cgit v1.2.3 From b2e8aa52e27ba518478099ed2eb98a3df85f42dd Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Fri, 7 Apr 2017 15:38:40 +0200 Subject: staging: most: usb: pass correct register table Inside the function store_value() the table of writable registers need to be passed to function get_static_reg_addr() or else the correct register address is never going to be found. Reported-by: Alex Riesen Signed-off-by: Christian Gromm Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/hdm-usb/hdm_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c index ad907e9c59bb..477c0ed305d3 100644 --- a/drivers/staging/most/hdm-usb/hdm_usb.c +++ b/drivers/staging/most/hdm-usb/hdm_usb.c @@ -1005,7 +1005,7 @@ static ssize_t store_value(struct most_dci_obj *dci_obj, err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val); else if (!strcmp(name, "sync_ep")) err = start_sync_ep(usb_dev, val); - else if (!get_static_reg_addr(ro_regs, name, ®_addr)) + else if (!get_static_reg_addr(rw_regs, name, ®_addr)) err = drci_wr_reg(usb_dev, reg_addr, val); else return -EFAULT; -- cgit v1.2.3 From f06ee95ce6b0b09c30e9344ca736d00d068c435c Mon Sep 17 00:00:00 2001 From: Dhananjay Balan Date: Mon, 24 Apr 2017 15:54:05 +0200 Subject: staging: most: aim-sound style fixess Replace hardcoded function name with __func__ Signed-off-by: Dhananjay Balan Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/aim-sound/sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/aim-sound/sound.c b/drivers/staging/most/aim-sound/sound.c index e4198e5e064b..ea1366a44008 100644 --- a/drivers/staging/most/aim-sound/sound.c +++ b/drivers/staging/most/aim-sound/sound.c @@ -429,7 +429,7 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) return 0; default: - pr_info("pcm_trigger(), invalid\n"); + pr_info("%s(), invalid\n", __func__); return -EINVAL; } return 0; -- cgit v1.2.3