06 Jun, 2019

1 commit

  • One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:

    struct objagg_stats {
    ...
    struct objagg_obj_stats_info stats_info[];
    };

    size = sizeof(*objagg_stats) + sizeof(objagg_stats->stats_info[0]) * count;
    instance = kzalloc(size, GFP_KERNEL);

    Instead of leaving these open-coded and prone to type mistakes, we can
    now use the new struct_size() helper:

    instance = kzalloc(struct_size(instance, stats_info, count), GFP_KERNEL);

    Notice that, in this case, variable alloc_size is not necessary, hence it
    is removed.

    This code was detected with the help of Coccinelle.

    Signed-off-by: Gustavo A. R. Silva
    Acked-by: Jiri Pirko
    Signed-off-by: David S. Miller

    Gustavo A. R. Silva
     

15 Feb, 2019

1 commit

  • It is possible that there might be an originally parent object with 0
    direct users that is in hints no longer considered as parent. Then the
    weight of this object is 0 and current code ignores him. That's why the
    total amount of hint objects might be lower than for the original
    objagg and WARN_ON is hit. Fix this be considering 0 weight valid.

    Fixes: 9069a3817d82 ("lib: objagg: implement optimization hints assembly and use hints for object creation")
    Signed-off-by: Jiri Pirko
    Reviewed-by: Ido Schimmel
    Signed-off-by: David S. Miller

    Jiri Pirko
     

14 Feb, 2019

1 commit

  • We need to set the error code on this path otherwise we return
    ERR_PTR(0) which would result in a NULL dereference in the caller.

    Fixes: 9069a3817d82 ("lib: objagg: implement optimization hints assembly and use hints for object creation")
    Signed-off-by: Dan Carpenter
    Acked-by: Jiri Pirko
    Signed-off-by: David S. Miller

    Dan Carpenter
     

09 Feb, 2019

3 commits

  • Count number of roots and add it to stats. It is handy for the library
    user to have this stats available as it can act upon it without
    counting roots itself.

    Signed-off-by: Jiri Pirko
    Signed-off-by: Ido Schimmel
    Signed-off-by: David S. Miller

    Jiri Pirko
     
  • Implement simple greedy algo to find more optimized root-delta tree for
    a given objagg instance. This "hints" can be used by a driver to:
    1) check if the hints are better (driver's choice) than the original
    objagg tree. Driver does comparison of objagg stats and hints stats.
    2) use the hints to create a new objagg instance which will construct
    the root-delta tree according to the passed hints. Currently, only a
    simple greedy algorithm is implemented. Basically it finds the roots
    according to the maximal possible user count including deltas.

    Signed-off-by: Jiri Pirko
    Signed-off-by: Ido Schimmel
    Signed-off-by: David S. Miller

    Jiri Pirko
     
  • Signed-off-by: Jiri Pirko
    Signed-off-by: Ido Schimmel
    Signed-off-by: David S. Miller

    Jiri Pirko
     

16 Nov, 2018

1 commit

  • This lib tracks objects which could be of two types:
    1) root object
    2) nested object - with a "delta" which differentiates it from
    the associated root object
    The objects are tracked by a hashtable and reference-counted. User is
    responsible of implementing callbacks to create/destroy root entity
    related to each root object and callback to create/destroy nested object
    delta.

    Signed-off-by: Jiri Pirko
    Signed-off-by: Ido Schimmel
    Signed-off-by: David S. Miller

    Jiri Pirko