svn commit: r300219 - in head/sys: kern sys

Steven Hartland steven at multiplay.co.uk
Thu May 19 18:51:49 UTC 2016


I thought it was considered better to use if (var == NULL) instead of
if (!var) for pointers as they aren't bools?

> On 19 May 2016, at 18:14, Scott Long <scottl at freebsd.org> wrote:
>
> Author: scottl
> Date: Thu May 19 17:14:24 2016
> New Revision: 300219
> URL: https://svnweb.freebsd.org/changeset/base/300219
>
> Log:
>  Adjust the creation of tq_name so it can be freed correctly
>
>  Reviewed by:    jhb, allanjude
>  Differential Revision:    D6454
>
> Modified:
>  head/sys/kern/subr_taskqueue.c
>  head/sys/sys/taskqueue.h
>
> Modified: head/sys/kern/subr_taskqueue.c
> ==============================================================================
> --- head/sys/kern/subr_taskqueue.c    Thu May 19 17:02:33 2016    (r300218)
> +++ head/sys/kern/subr_taskqueue.c    Thu May 19 17:14:24 2016    (r300219)
> @@ -128,16 +128,17 @@ _taskqueue_create(const char *name, int
>         int mtxflags, const char *mtxname __unused)
> {
>    struct taskqueue *queue;
> -    char *tq_name = NULL;
> +    char *tq_name;
>
> -    if (name != NULL)
> -        tq_name = strndup(name, 32, M_TASKQUEUE);
> -    if (tq_name == NULL)
> -        tq_name = "taskqueue";
> +    tq_name = malloc(TASKQUEUE_NAMELEN, M_TASKQUEUE, mflags | M_ZERO);
> +    if (!tq_name)
> +        return (NULL);
> +
> +    snprintf(tq_name, TASKQUEUE_NAMELEN, "%s", (name) ? name : "taskqueue");
>
>    queue = malloc(sizeof(struct taskqueue), M_TASKQUEUE, mflags | M_ZERO);
>    if (!queue)
> -        return NULL;
> +        return (NULL);
>
>    STAILQ_INIT(&queue->tq_queue);
>    TAILQ_INIT(&queue->tq_active);
> @@ -153,7 +154,7 @@ _taskqueue_create(const char *name, int
>        queue->tq_flags |= TQ_FLAGS_UNLOCKED_ENQUEUE;
>    mtx_init(&queue->tq_mutex, tq_name, NULL, mtxflags);
>
> -    return queue;
> +    return (queue);
> }
>
> struct taskqueue *
>
> Modified: head/sys/sys/taskqueue.h
> ==============================================================================
> --- head/sys/sys/taskqueue.h    Thu May 19 17:02:33 2016    (r300218)
> +++ head/sys/sys/taskqueue.h    Thu May 19 17:14:24 2016    (r300219)
> @@ -56,6 +56,7 @@ enum taskqueue_callback_type {
> #define    TASKQUEUE_CALLBACK_TYPE_MIN    TASKQUEUE_CALLBACK_TYPE_INIT
> #define    TASKQUEUE_CALLBACK_TYPE_MAX    TASKQUEUE_CALLBACK_TYPE_SHUTDOWN
> #define    TASKQUEUE_NUM_CALLBACKS        TASKQUEUE_CALLBACK_TYPE_MAX + 1
> +#define    TASKQUEUE_NAMELEN        32
>
> typedef void (*taskqueue_callback_fn)(void *context);
>
>


More information about the svn-src-head mailing list