From patchwork Thu May 26 17:01:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Saxena X-Patchwork-Id: 576439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 613AFC433EF for ; Thu, 26 May 2022 17:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347040AbiEZRCW (ORCPT ); Thu, 26 May 2022 13:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241138AbiEZRCV (ORCPT ); Thu, 26 May 2022 13:02:21 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D8E2CDF8 for ; Thu, 26 May 2022 10:02:19 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id qe5-20020a17090b4f8500b001e26126abccso810700pjb.0 for ; Thu, 26 May 2022 10:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:mime-version; bh=yJDq5hM8f418dXRMEODCQdwy1k0fWBpn+oMHS+HGiJA=; b=Syh+u0gY/qzqI6nVkehrPEROhrLxKONHGGkcsgLiWEqbhoIXZ1W+HW3Fg/PJWIM4JR uk6H6Za74t81bOH/OElk2t9P3/ymTilGuDFHjkqn2kCXSHCo/ak+E+MTNSwtVJ94i2lU mc2+TsVOn62tV/+E1f03p3UGpuRHwaG7eCSrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=yJDq5hM8f418dXRMEODCQdwy1k0fWBpn+oMHS+HGiJA=; b=cyrrunWdzRxkw9dBaXKBg5POJ6ji4L2l+JXQC7bMY8BHuDnI7lOQ9urLuschOPBlm3 lfcvaRiXZkP7CHvUlCvF4/cXDHkJH0u34mmG4UWHZGC7FZbS6Ejrhs1P3AhiahdILuBi OEm7ec3m8RA//U6XrEQ9KZt2x8ShB/ml3naHNoqyhmWWKT52lIAykbW5QDTov10oDn1Z UPAlot5lPUayDaG28RKBh5jGtas0ZXmaRSROs3GpWhKfUZDNitykquahPvpleMiN5V5B E0TZWQ8VkTFodSfCAXQteTy07xh/w5n0bu2fZnCUKlhrlLzXN24UW47rdITwWKRepUpI SsJQ== X-Gm-Message-State: AOAM532eorVSloAfOZvpl6wgq9IwwnvU1EhQJtEKXCnlQNf9x3KZaNFe TN2zVT/EpxxXZ/JapBYxnmXSJv0jl400pYDXbsCN5BDZEoWR7C6wPIPxd0rHwV7oS1iDP4JwYmg vysvM3qOVVBZoRPYp6DWDQE38lbV21FBgtPsp9xbg5awGK51dc6I6TH6B8k+DTnzdXoMw6NlWon rIy2tCQSI= X-Google-Smtp-Source: ABdhPJydV9uH2o70DC+vPVj9Z1d7PJ+c8hVgugowehS+BCE+UL1/AbB9K8/3g59bWFmctfFI5yqceA== X-Received: by 2002:a17:903:40d0:b0:163:62a5:3356 with SMTP id t16-20020a17090340d000b0016362a53356mr7566235pld.146.1653584538885; Thu, 26 May 2022 10:02:18 -0700 (PDT) Received: from dhcp-10-123-20-15.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id h4-20020a17090a3d0400b001df5dea7d4bsm3957712pjc.43.2022.05.26.10.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 10:02:18 -0700 (PDT) From: Sumit Saxena To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, Sumit Saxena , Dan Carpenter Subject: [PATCH] mpi3mr: rework mrioc->bsg_device model to fix up smatch warnings Date: Thu, 26 May 2022 13:01:57 -0400 Message-Id: <20220526170157.58274-1-sumit.saxena@broadcom.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org During driver unload, "mrioc->bsg_device" reference count becomes negative. Also, as reported in [1], driver's bsg_device model had few more bugs so reworked it to fix up them. [1] https://marc.info/?l=linux-scsi&m=165183971411991&w=2 Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support") Reported-by: Dan Carpenter Signed-off-by: Sumit Saxena Tested-by: Tomas Henzl --- drivers/scsi/mpi3mr/mpi3mr.h | 2 +- drivers/scsi/mpi3mr/mpi3mr_app.c | 48 +++++++++++++++----------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index 01cd01787b0f..0e1cb4aa4ca2 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -954,7 +954,7 @@ struct mpi3mr_ioc { u16 active_poll_qcount; u16 requested_poll_qcount; - struct device *bsg_dev; + struct device bsg_dev; struct request_queue *bsg_queue; u8 stop_bsgs; u8 *logdata_buf; diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c index 9ab1762468ad..29ed64a572ea 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_app.c +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c @@ -1487,28 +1487,28 @@ static int mpi3mr_bsg_request(struct bsg_job *job) */ void mpi3mr_bsg_exit(struct mpi3mr_ioc *mrioc) { + struct device *bsg_dev = &mrioc->bsg_dev; if (!mrioc->bsg_queue) return; bsg_remove_queue(mrioc->bsg_queue); mrioc->bsg_queue = NULL; - device_del(mrioc->bsg_dev); - put_device(mrioc->bsg_dev); - kfree(mrioc->bsg_dev); + device_del(bsg_dev); + put_device(bsg_dev); } /** * mpi3mr_bsg_node_release -release bsg device node * @dev: bsg device node * - * decrements bsg dev reference count + * decrements bsg dev parent reference count * * Return:Nothing */ static void mpi3mr_bsg_node_release(struct device *dev) { - put_device(dev); + put_device(dev->parent); } /** @@ -1521,41 +1521,37 @@ static void mpi3mr_bsg_node_release(struct device *dev) */ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc) { - mrioc->bsg_dev = kzalloc(sizeof(struct device), GFP_KERNEL); - if (!mrioc->bsg_dev) { - ioc_err(mrioc, "bsg device mem allocation failed\n"); - return; - } + struct device *bsg_dev = &mrioc->bsg_dev; + struct device *parent = &mrioc->shost->shost_gendev; + + device_initialize(bsg_dev); + + bsg_dev->parent = get_device(parent); + bsg_dev->release = mpi3mr_bsg_node_release; - device_initialize(mrioc->bsg_dev); - dev_set_name(mrioc->bsg_dev, "mpi3mrctl%u", mrioc->id); + dev_set_name(bsg_dev, "mpi3mrctl%u", mrioc->id); - if (device_add(mrioc->bsg_dev)) { + if (device_add(bsg_dev)) { ioc_err(mrioc, "%s: bsg device add failed\n", - dev_name(mrioc->bsg_dev)); - goto err_device_add; + dev_name(bsg_dev)); + put_device(bsg_dev); + return; } - mrioc->bsg_dev->release = mpi3mr_bsg_node_release; - - mrioc->bsg_queue = bsg_setup_queue(mrioc->bsg_dev, dev_name(mrioc->bsg_dev), + mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), mpi3mr_bsg_request, NULL, 0); if (IS_ERR(mrioc->bsg_queue)) { ioc_err(mrioc, "%s: bsg registration failed\n", - dev_name(mrioc->bsg_dev)); - goto err_setup_queue; + dev_name(bsg_dev)); + device_del(bsg_dev); + put_device(bsg_dev); + return; } blk_queue_max_segments(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SEGMENTS); blk_queue_max_hw_sectors(mrioc->bsg_queue, MPI3MR_MAX_APP_XFER_SECTORS); return; - -err_setup_queue: - device_del(mrioc->bsg_dev); - put_device(mrioc->bsg_dev); -err_device_add: - kfree(mrioc->bsg_dev); } /**