Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3752202imm; Mon, 4 Jun 2018 08:42:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7DLcuTk130KevFGRrPK9n2oKIV+6h0/IfcpwOdKPSV3v9Qt+O880xP14GmOqUmCfjQiLt X-Received: by 2002:a62:d388:: with SMTP id z8-v6mr22069927pfk.8.1528126950218; Mon, 04 Jun 2018 08:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528126950; cv=none; d=google.com; s=arc-20160816; b=DlRYEr5jO9TmeU1asBE8IJpQCozfCkJ0Xfl0wh35rH0VEVCpHFMBiCShva2h9e/WTz 023OsknofqIjJqKYEvUgdom0vyqJsNv7/uKW+noudcTaOFIWB72c8QUTrJB/MydH2HJu tRthfnZ6Gv0g/FFq6qX9QzqeREo/snDF9NieJwgCJzeufOxCdOLW0U8MjDhbZIOci7id jIKMRjszbKIpErtPT7ADE19zdZ+zfSyr6jN7/0T+DPkt7NNJGQuyceLkcVvp4aw4IEbY I1WRgi7FT60oZZu11jZ/TQvywFj+Hbm/V4fEhm9wuvi5F6mfGKPtP8iSqRE4yC9ITVxO prqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=VPIXfDK2Y0IWDqCi7pgtfwBz/fLVxODTuDhfWovilMQ=; b=EM6ImfAl/N3vDGosKWWKebfN+2DXKilN3v4PmNJUImOchJBavoycLzc1sQPfVqfj5k k5BJa/2bbvJRj6FXy3VyZ8G/VfoaTKeJzh2E1KANkj+A65DMDothOf8OyCrs36UdzDQh nMalFAZ6RKShvJmOAhrTHR4odnZRBD55oXf4Uaelx+LtCJ9lvI1yeP9B2vPV1F+LgEQ8 jQO6XaICDMeWuBFKe7FsLv7mX17dxD0T4UkmQB373PpLv8RrFaRBf2MLdnYiHf5zkaSt d0oBsdqRPgGco8CyRwThyqrpbo5tyFLF3DCQmMYMd6dISdZnKjPc16tPCOxEGBPy8Vhi SB2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Det+jA+n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19-v6si45426525plo.287.2018.06.04.08.42.16; Mon, 04 Jun 2018 08:42:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Det+jA+n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751434AbeFDPlh (ORCPT + 99 others); Mon, 4 Jun 2018 11:41:37 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:38461 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbeFDPlf (ORCPT ); Mon, 4 Jun 2018 11:41:35 -0400 Received: by mail-ot0-f193.google.com with SMTP id n3-v6so38207400ota.5 for ; Mon, 04 Jun 2018 08:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VPIXfDK2Y0IWDqCi7pgtfwBz/fLVxODTuDhfWovilMQ=; b=Det+jA+naOeESCLJWsS4C73eol7rzdNJPPpgGsQMqa9mRz/q/ZXHEXIZRcpGadGGHt yb7D78eiWk6H+/fMNK0+bJtoL9w87B0ERnASQKrPHTdMg5TllcjGSenm7jVmmRiIiOR8 H3deie1ELtMyEDZXJvhXJcFtUmqe9o8+0VXm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VPIXfDK2Y0IWDqCi7pgtfwBz/fLVxODTuDhfWovilMQ=; b=OSdja3JdJWyJNXQP2jAYaKfJ8QRhiMGYFdRInWFUG1uw3NV1dXZ1rEAePQ0EOUWoa0 CqRUaGaSuAZSv/aEhtZcabksDUr2PQBGQJCwjzvE+FCrpo+W7UhoqPtQmuqoumq4xBSS 7rpzFSAwPMvvV1GNtSigm1igGHzwv2cF1PbcrU3dGPaZ2NcFNhuB7CfoMuNMF7CznvVi nzKw6D8G9s2mhkERFZglip8bBlA3WbV2lTpEmajc5qpkqP5VLYiP+DkMOCh/EFOE8oVi afAVtXlzqrChXRa7ar0G3VRJ8yOc48PhJLd0Ce92KQAZt4SpeQO+3lL+uuDk+o6Hy7vb Bz5A== X-Gm-Message-State: APt69E0sZEH+fVsRfgYJzW1y5GwrvGxm8nKP0CSwst1EQMAdHKjTVG32 QYBwwdrqTZaY50fu4d/G5EOQI+8PG8w= X-Received: by 2002:a9d:3835:: with SMTP id i50-v6mr9877871otc.382.1528126895130; Mon, 04 Jun 2018 08:41:35 -0700 (PDT) Received: from mail-oi0-f46.google.com (mail-oi0-f46.google.com. [209.85.218.46]) by smtp.gmail.com with ESMTPSA id z44-v6sm3881974otc.46.2018.06.04.08.41.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 08:41:34 -0700 (PDT) Received: by mail-oi0-f46.google.com with SMTP id e8-v6so10646987oii.2 for ; Mon, 04 Jun 2018 08:41:33 -0700 (PDT) X-Received: by 2002:aca:bb8a:: with SMTP id l132-v6mr6381513oif.5.1528126893324; Mon, 04 Jun 2018 08:41:33 -0700 (PDT) MIME-Version: 1.0 References: <20180529181740.195362-1-evgreen@chromium.org> <20180529181740.195362-6-evgreen@chromium.org> <21ce321eb2d81d59d6e4578669b8287b9ac4d29f.camel@wdc.com> In-Reply-To: <21ce321eb2d81d59d6e4578669b8287b9ac4d29f.camel@wdc.com> From: Evan Green Date: Mon, 4 Jun 2018 08:40:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 5/7] scsi: ufs: Refactor descriptor read for write To: Bart.VanAssche@wdc.com Cc: jejb@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, Vinayak Holikatti , Stanislav.Nijnikov@wdc.com, Gwendal Grignou Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 4, 2018 at 1:41 AM Bart Van Assche wrote: > > On Tue, 2018-05-29 at 11:17 -0700, Evan Green wrote: > > /* Check whether we need temp memory */ > > if (param_offset != 0 || param_size < buff_len) { > > - desc_buf = kmalloc(buff_len, GFP_KERNEL); > > + desc_buf = kzalloc(buff_len, GFP_KERNEL); > > if (!desc_buf) > > return -ENOMEM; > > + > > + /* If it's a write, first read the complete descriptor, then > > + * copy in the parts being changed. > > + */ > > Have you verified this patch with checkpatch? The above comment does not follow > the Linux kernel coding style. Yes, but I probably forgot to add that switch that turns on even more checks. Will fix. > > > + if (opcode == UPIU_QUERY_OPCODE_WRITE_DESC) { > > + if ((int)param_offset + (int)param_size > buff_len) { > > + ret = -EINVAL; > > + goto out; > > + } > > + > > + ret = ufshcd_query_descriptor_retry(hba, > > + UPIU_QUERY_OPCODE_READ_DESC, > > + desc_id, desc_index, 0, > > + desc_buf, &buff_len); > > + > > + if (ret) { > > + dev_err(hba->dev, > > + "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d", > > + __func__, desc_id, desc_index, > > + param_offset, ret); > > + > > + goto out; > > + } > > + > > + memcpy(desc_buf + param_offset, param_buf, param_size); > > + } > > The above code is indented deeply. I think that means that this code would become > easier to read if a helper function would be introduced. Ok. > > Additionally, I think locking is missing from the above code. How else can race > conditions between concurrent writers be prevented? Hm, yeah I think this followed along with my thinking that there wouldn't be multiple processes provisioning at once. This function will always write a consistent version of one caller's view, but multiple callers might clobber each other's writes. I can explore adding locking. -Evan