From patchwork Fri May 15 03:41:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Owens X-Patchwork-Id: 6411021 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 95634C0432 for ; Fri, 15 May 2015 03:44:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBBB920306 for ; Fri, 15 May 2015 03:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E677320303 for ; Fri, 15 May 2015 03:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933945AbbEODms (ORCPT ); Thu, 14 May 2015 23:42:48 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:62159 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933705AbbEODmp (ORCPT ); Thu, 14 May 2015 23:42:45 -0400 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t4F3bSLm011715; Thu, 14 May 2015 20:42:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=W7IWgh4E34GwAHB2/evyZEDSlmryGywoIQu4YrzoQz8=; b=LNz3xbP0QlbDVGXFwyTde+5oUDxQBDhxS6gjc23GTj/2llPwHr+Dy1LkSYGX0BnuHIgT Wigzb956R0pn0ak/tPHJPkgEW/X6BWT48lrkFEHhI3byJ9xRthFLctq+Rzu4fPTovNPQ T7VX8S+2gD2NkuPRFO+JuNL96iDdqjuEb/A= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1ud79tr7t7-2 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 14 May 2015 20:42:42 -0700 Received: from devbig030.prn2.facebook.com (192.168.52.13) by PRN-CHUB04.TheFacebook.com (192.168.16.14) with Microsoft SMTP Server id 14.3.195.1; Thu, 14 May 2015 20:42:35 -0700 From: Calvin Owens To: Nagalakshmi Nandigama , Praveen Krishnamoorthy , Sreekanth Reddy , Abhijit Mahajan CC: , , , , Subject: [PATCH 1/6] Add refcount to sas_device struct Date: Thu, 14 May 2015 20:41:57 -0700 Message-ID: <1431661322-3097935-2-git-send-email-calvinowens@fb.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1431661322-3097935-1-git-send-email-calvinowens@fb.com> References: <20150506184852.GA1007288@mail.thefacebook.com> <1431661322-3097935-1-git-send-email-calvinowens@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.52.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151, 1.0.33, 0.0.0000 definitions=2015-05-15_01:2015-05-14, 2015-05-15, 1970-01-01 signatures=0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP These objects can be referenced concurrently throughout the driver, we need a way to make sure threads can't delete them out from under each other. Signed-off-by: Calvin Owens --- drivers/scsi/mpt2sas/mpt2sas_base.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h index caff8d1..2e7dc33 100644 --- a/drivers/scsi/mpt2sas/mpt2sas_base.h +++ b/drivers/scsi/mpt2sas/mpt2sas_base.h @@ -376,8 +376,24 @@ struct _sas_device { u8 phy; u8 responding; u8 pfa_led_on; + struct kref refcount; }; +static inline void sas_device_get(struct _sas_device *s) +{ + kref_get(&s->refcount); +} + +static inline void sas_device_free(struct kref *r) +{ + kfree(container_of(r, struct _sas_device, refcount)); +} + +static inline void sas_device_put(struct _sas_device *s) +{ + kref_put(&s->refcount, sas_device_free); +} + /** * struct _raid_device - raid volume link list * @list: sas device list