From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932141AbdJXPzD (ORCPT ); Tue, 24 Oct 2017 11:55:03 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:46958 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751427AbdJXPzB (ORCPT ); Tue, 24 Oct 2017 11:55:01 -0400 X-Google-Smtp-Source: ABhQp+T0JgAm/wrhK+QugqdcB/AIXblaRT20bxc7BPuL5JngYVPULD0Cvr601qWzrSSlIoWxSm9znQ== Subject: Re: [PATCH v2] staging: greybus: Convert timers to use timer_setup() To: Kees Cook , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Johan Hovold , Alex Elder , greybus-dev@lists.linaro.org, devel@driverdev.osuosl.org References: <20171024144938.GA41224@beast> From: "Bryan O'Donoghue" Message-ID: <55a6647a-8565-09e8-9f45-d9048c7dd916@linaro.org> Date: Tue, 24 Oct 2017 16:54:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20171024144938.GA41224@beast> Content-Type: multipart/mixed; boundary="------------174878EFA493E8B3CE607B1A" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------174878EFA493E8B3CE607B1A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 24/10/17 15:49, Kees Cook wrote: > In preparation for unconditionally passing the struct timer_list pointer to > all timer callbacks, switch to using the new timer_setup() and from_timer() > to pass the timer pointer explicitly. > > Cc: Greg Kroah-Hartman > Cc: "Bryan O'Donoghue" > Cc: Johan Hovold > Cc: Alex Elder > Cc: greybus-dev@lists.linaro.org > Cc: devel@driverdev.osuosl.org > Signed-off-by: Kees Cook > --- > v2: Added back "get" in timer code, thanks to Bryan. :) > --- > drivers/staging/greybus/loopback.c | 19 +++++++++---------- > drivers/staging/greybus/operation.c | 7 +++---- > 2 files changed, 12 insertions(+), 14 deletions(-) > > diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c > index 08e255884206..1c0bafeb7ea5 100644 > --- a/drivers/staging/greybus/loopback.c > +++ b/drivers/staging/greybus/loopback.c > @@ -572,16 +572,16 @@ static void gb_loopback_async_operation_work(struct work_struct *work) > gb_loopback_async_operation_put(op_async); > } > > -static void gb_loopback_async_operation_timeout(unsigned long data) > +static void gb_loopback_async_operation_timeout(struct timer_list *t) > { > - struct gb_loopback_async_operation *op_async; > - u16 id = data; > + struct gb_loopback_async_operation *op_async = > + from_timer(op_async, t, timer); > + unsigned long flags; > + > + spin_lock_irqsave(&gb_dev.lock, flags); > + gb_loopback_async_operation_get(op_async); > + spin_unlock_irqrestore(&gb_dev.lock, flags); Damnit I'm just wrong (I hate that). The pointer can already have gone away by the time the timer runs - my bad... see attached for update - with my Signed-off added. --- bod --------------174878EFA493E8B3CE607B1A Content-Type: text/x-patch; name="0001-staging-greybus-Convert-timers-to-use-timer_setup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-staging-greybus-Convert-timers-to-use-timer_setup.patch" >>From aa9fbf091122c816a47de2aece5412f7fd9225a9 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 24 Oct 2017 07:49:38 -0700 Subject: [PATCH] staging: greybus: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Cc: Greg Kroah-Hartman Cc: "Bryan O'Donoghue" Cc: Johan Hovold Cc: Alex Elder Cc: greybus-dev@lists.linaro.org Cc: devel@driverdev.osuosl.org Signed-off-by: Kees Cook Signed-off-by: Bryan O'Donoghue --- drivers/staging/greybus/loopback.c | 38 ++++++++++++++++++++++++++----------- drivers/staging/greybus/operation.c | 7 +++---- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c index 08e2558..81447e3 100644 --- a/drivers/staging/greybus/loopback.c +++ b/drivers/staging/greybus/loopback.c @@ -472,6 +472,26 @@ static void gb_loopback_async_operation_put(struct gb_loopback_async_operation spin_unlock_irqrestore(&gb_dev.lock, flags); } +static struct gb_loopback_async_operation *gb_loopback_async_operation_valid( + struct gb_loopback_async_operation *op_async) +{ + struct gb_loopback_async_operation *op_async_tmp; + bool found = false; + unsigned long flags; + + spin_lock_irqsave(&gb_dev.lock, flags); + list_for_each_entry(op_async_tmp, &gb_dev.list_op_async, entry) { + if (op_async_tmp == op_async) { + gb_loopback_async_operation_get(op_async); + found = true; + break; + } + } + spin_unlock_irqrestore(&gb_dev.lock, flags); + + return found ? op_async : NULL; +} + static struct gb_loopback_async_operation * gb_loopback_operation_find(u16 id) { @@ -572,17 +592,14 @@ static void gb_loopback_async_operation_work(struct work_struct *work) gb_loopback_async_operation_put(op_async); } -static void gb_loopback_async_operation_timeout(unsigned long data) +static void gb_loopback_async_operation_timeout(struct timer_list *t) { - struct gb_loopback_async_operation *op_async; - u16 id = data; + struct gb_loopback_async_operation *op_async = + from_timer(op_async, t, timer); - op_async = gb_loopback_operation_find(id); - if (!op_async) { - pr_err("operation %d not found - time out ?\n", id); - return; - } - schedule_work(&op_async->work); + op_async = gb_loopback_async_operation_valid(op_async); + if (op_async) + schedule_work(&op_async->work); } static int gb_loopback_async_operation(struct gb_loopback *gb, int type, @@ -631,8 +648,7 @@ static int gb_loopback_async_operation(struct gb_loopback *gb, int type, if (ret) goto error; - setup_timer(&op_async->timer, gb_loopback_async_operation_timeout, - (unsigned long)operation->id); + timer_setup(&op_async->timer, gb_loopback_async_operation_timeout, 0); op_async->timer.expires = jiffies + gb->jiffy_timeout; add_timer(&op_async->timer); diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 3023012..ee4ba3f 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -294,9 +294,9 @@ static void gb_operation_work(struct work_struct *work) gb_operation_put(operation); } -static void gb_operation_timeout(unsigned long arg) +static void gb_operation_timeout(struct timer_list *t) { - struct gb_operation *operation = (void *)arg; + struct gb_operation *operation = from_timer(operation, t, timer); if (gb_operation_result_set(operation, -ETIMEDOUT)) { /* @@ -541,8 +541,7 @@ gb_operation_create_common(struct gb_connection *connection, u8 type, goto err_request; } - setup_timer(&operation->timer, gb_operation_timeout, - (unsigned long)operation); + timer_setup(&operation->timer, gb_operation_timeout, 0); } operation->flags = op_flags; -- 2.7.4 --------------174878EFA493E8B3CE607B1A--