From patchwork Wed May 20 13:52:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 48800 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E97A12121F for ; Wed, 20 May 2015 13:53:11 +0000 (UTC) Received: by wgcz3 with SMTP id z3sf11547490wgc.3 for ; Wed, 20 May 2015 06:53:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=g2GdTwC2lSd3SdBBgSbjlSRcz+ZKPcF75jAwGgcp4Ys=; b=JGsLrJbk14YvrgIZ+wqxSPbW0tSz5u4wUuMmlTcZLx364Cwcd3BSwbVfJ9LFUdMWEV 53RafLLYwxw1ReoTMMEdPGhiPDfqZ40zrjum7uyp7WEIOSeP0hC0yIvJw7aa6kMxPXP5 lJUCyaD7t17tHy5LZljXBcUIMUh19d0xvxbaK288E6E370ikrVvo857DNvwXBNp45enE pzoGnHeUuJnt5OA4J6fiQjRdSiBR9F7U/uDtqMHwLZJrLx7wvD7jSvLc+BgCgF4KPPyR SULGsPgJM3bNwUNS9crpqHDt6CgGm6KeRUiGzMmb+AnhBsapO0pFxj1Vlv+OX8u90drK BD+g== X-Gm-Message-State: ALoCoQmO4nGwQ6q4eTCZbxZNGVyXeAMHrwef+AIJ5FPKZeOxvIBgSl7tiiWhdkhizr/5xre+b2Od X-Received: by 10.112.28.111 with SMTP id a15mr26484236lbh.21.1432129991220; Wed, 20 May 2015 06:53:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.39 with SMTP id kv7ls199731lac.63.gmail; Wed, 20 May 2015 06:53:11 -0700 (PDT) X-Received: by 10.152.88.80 with SMTP id be16mr25680107lab.39.1432129991070; Wed, 20 May 2015 06:53:11 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id l8si11215994lah.54.2015.05.20.06.53.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 May 2015 06:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labbd9 with SMTP id bd9so75436614lab.2 for ; Wed, 20 May 2015 06:53:10 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr26143239lbc.86.1432129990562; Wed, 20 May 2015 06:53:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1547631lbb; Wed, 20 May 2015 06:53:09 -0700 (PDT) X-Received: by 10.70.133.66 with SMTP id pa2mr64806100pdb.164.1432129988471; Wed, 20 May 2015 06:53:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bk1si26630297pad.104.2015.05.20.06.53.07; Wed, 20 May 2015 06:53:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752451AbbETNxE (ORCPT + 4 others); Wed, 20 May 2015 09:53:04 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:34356 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927AbbETNxD (ORCPT ); Wed, 20 May 2015 09:53:03 -0400 Received: by wghq2 with SMTP id q2so53731795wgh.1 for ; Wed, 20 May 2015 06:53:02 -0700 (PDT) X-Received: by 10.180.73.202 with SMTP id n10mr42957353wiv.0.1432129982765; Wed, 20 May 2015 06:53:02 -0700 (PDT) Received: from arch-late.dtvresearch.loc (a95-92-118-66.cpe.netcabo.pt. [95.92.118.66]) by mx.google.com with ESMTPSA id x3sm3594717wiy.20.2015.05.20.06.53.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 May 2015 06:53:01 -0700 (PDT) From: Rui Miguel Silva To: Felipe Balbi Cc: linux-usb@vger.kernel.org, Greg Kroah-Hartman , Rui Miguel Silva Subject: [PATCH] usb: gadget: f_fs: add extra check before unregister_gadget_item Date: Wed, 20 May 2015 14:52:40 +0100 Message-Id: <1432129960-21909-1-git-send-email-rui.silva@linaro.org> X-Mailer: git-send-email 2.4.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rui.silva@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ffs_closed can race with configfs_rmdir which will call config_item_release, so add an extra check to avoid calling the unregister_gadget_item with an null gadget item. Signed-off-by: Rui Miguel Silva --- drivers/usb/gadget/function/f_fs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index fa538fa..8f893cd 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3435,6 +3435,7 @@ done: static void ffs_closed(struct ffs_data *ffs) { struct ffs_dev *ffs_obj; + struct f_fs_opts *opts; ENTER(); ffs_dev_lock(); @@ -3448,8 +3449,13 @@ static void ffs_closed(struct ffs_data *ffs) if (ffs_obj->ffs_closed_callback) ffs_obj->ffs_closed_callback(ffs); - if (!ffs_obj->opts || ffs_obj->opts->no_configfs - || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) + if (ffs_obj->opts) + opts = ffs_obj->opts; + else + goto done; + + if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent + || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) goto done; unregister_gadget_item(ffs_obj->opts->