Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1245460imm; Fri, 11 May 2018 13:18:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqNyd8sBnEfobHIomUKtV3EpsVwBM61N7G4IOXWAodVH8bNulH6fLEqUFnTikeCfEQTYVog X-Received: by 2002:a65:6414:: with SMTP id a20-v6mr395052pgv.226.1526069934252; Fri, 11 May 2018 13:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526069934; cv=none; d=google.com; s=arc-20160816; b=jTjrv8R1fdEUPMKtaVIZcCVKwKpIyYVAAXs7KTqrBaMDzAq8452bKGZAMp1YI3qqqQ 1zD/LFrxFQNWkXQsNCxhrc2rHa2ptyIa4zNVPi6pnRcjk98ctFbXKbDsww19AbkGjUWm 6ImcwFrw9/cgu8zTKZ81CK4BaoxToHV7AJAhtK2B8E/kN9RNBvKj4dr/LGjlPBSLpZeK Vr7go9KEki4thzRbAq5A1YwEG+ls70EeIRM8c3qvNckfftKIOUadMRgTdMBWNk8lJUYs bOQG1J24ETdjMS8CqNYGAxV/nGjoY3ADYzFiCHtedx7CUmAYu8nEkRbIhzoLeSYnR7gx cMDA== 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 :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=+oUXNblDjiS7kgQ9+mUot2MI8y2OtMBKauGwFUJUGeA=; b=Kt80YHZCc6jygHzl8XBcgfLsQ/Uasvq9scbzNt/shPYvRi1mTgXQZnVfgXY1/px7eP Om7TfWlI7u4u4qWvFwscAKajNopdiYDkIuvW3LvaoyHtMmXPl9/T+IrouTXeKEhlpnJ/ 2/Dv3fe96ip14VDUE4N57XptLAFv2TnE4DrbTQflmy0VzkswNwIEAgnSQOhtyieh/H95 EWF7F+TJfwvpMkmc9X30KUDb8cKbcuukp8dgynkfwFWG385wTv83o2PTIm6phodfVEfh Bt3gyIbFRQXqRjI3lN0/7VyqiulxyhQGNlPntbm6fYVzcgS6ltNadnBVJQhqwDqX2pDy K+2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=Me+iIzig; dkim=fail header.i=@chromium.org header.s=google header.b=PHp8tx86; 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=fail (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 r16-v6si3030547pgr.560.2018.05.11.13.18.40; Fri, 11 May 2018 13:18:54 -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=fail header.i=@google.com header.s=20161025 header.b=Me+iIzig; dkim=fail header.i=@chromium.org header.s=google header.b=PHp8tx86; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752019AbeEKURS (ORCPT + 99 others); Fri, 11 May 2018 16:17:18 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:41286 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeEKURQ (ORCPT ); Fri, 11 May 2018 16:17:16 -0400 Received: by mail-vk0-f68.google.com with SMTP id 131-v6so3992530vkf.8 for ; Fri, 11 May 2018 13:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=+oUXNblDjiS7kgQ9+mUot2MI8y2OtMBKauGwFUJUGeA=; b=Me+iIzig4tVfSKVDFYpJ6xLY4ajgmdxPHaQBpyyRnVyQRL+nkCFLJKs6F3lyKzpVG8 cy4IGj0E3Ykgi7S7HMBWGrLY9cg3NpQaE9xUhETa0yrzs+OoMAIYo+mTNwdJGIOAb4dm 0664nhQVZqy3yY8XJk2kUh+szcsNCaNn9NzWI/B8NWeIGMukrD4uwSC/B3Oa/5zShK41 Lb8PiU2lDpkJGed7zMbmteuDOfhsci9AbIVfW7j78xuFZnlT6gyTeAHdVXl8EPG2kJKh nFH6mN5+0O70LjSAIzcGxiwGlBxfI1l/VqwwNLzH2uPaLVwjwDESw6rhAZkjBTzYHrhg xxLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=+oUXNblDjiS7kgQ9+mUot2MI8y2OtMBKauGwFUJUGeA=; b=PHp8tx86IBGPKqgzwgJMxEzlKW3sEVy1peTpUyjvZrXS2E1/dg7+0eDZNaRPVPm00K eZ7Luo0hPo+6uvpmkSjgWNspGQtWcejohJWhDZka8HR8T5e9ywdU6Ur5fEjMDm8Osx3X yFo3Sb9e3Wb1jyvZi4/yJH2kgFxKQ4E7z4zQQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=+oUXNblDjiS7kgQ9+mUot2MI8y2OtMBKauGwFUJUGeA=; b=err6h4nLSSagkgjhKjhFpnp0ylASn7BtZEYYrbp39KUgv0XfcHR3rzEtf0eXVjeKWS hewckWPt3KcAz0w8UwMR3LAbmaySbj/xRkGDlTB3FvJdfoHs6KWQ5ndbnHFggWHo+V6n qW0MPil998XXWcx5RvkUXzugodEH7XjAdGT8H0ogni9z1gUYj6oESdcgukFtKRbWcjUM eMQy+S5tGVx7VVm3cd67nEXbvXrNfsvslwJT2Vi33/Ik4r4heQvD3MJ6cPUOE7VmeN8w guwMD8eqWiKzhAHPrpgrQX00LqyKXNTwqnBJk0dbFZTyZmW0QeAwNhIlofMq0cFn7xYU oOdg== X-Gm-Message-State: ALKqPwexaZPFMTgYe7Cu8xjC+8K7U5Cr1J6QKvf5xirWBkpP01lHa6qH wpgst/JNF5LigNScYf0+cz6u/o0zKCZxS5jdSK4KVg== X-Received: by 2002:a1f:1957:: with SMTP id 84-v6mr1213247vkz.90.1526069835402; Fri, 11 May 2018 13:17:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.48.82 with HTTP; Fri, 11 May 2018 13:17:14 -0700 (PDT) In-Reply-To: <20180509170159.29682-5-ilina@codeaurora.org> References: <20180509170159.29682-1-ilina@codeaurora.org> <20180509170159.29682-5-ilina@codeaurora.org> From: Doug Anderson Date: Fri, 11 May 2018 13:17:14 -0700 X-Google-Sender-Auth: WavOYWhSfQUMX-ZGj3xy6v9pNlM Message-ID: Subject: Re: [PATCH v8 04/10] drivers: qcom: rpmh: add RPMH helper functions To: Lina Iyer Cc: Andy Gross , David Brown , linux-arm-msm@vger.kernel.org, "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , Bjorn Andersson , LKML , Stephen Boyd , Evan Green , Matthias Kaehlcke , rplsssn@codeaurora.org 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 Hi, On Wed, May 9, 2018 at 10:01 AM, Lina Iyer wrote: > +int rpmh_write(const struct device *dev, enum rpmh_state state, > + const struct tcs_cmd *cmd, u32 n) > +{ > + DECLARE_COMPLETION_ONSTACK(compl); > + DEFINE_RPMH_MSG_ONSTACK(dev, state, &compl, rpm_msg); > + int ret; > + > + if (!cmd || !n || n > MAX_RPMH_PAYLOAD) > + return -EINVAL; > + > + memcpy(rpm_msg.cmd, cmd, n * sizeof(*cmd)); > + rpm_msg.msg.num_cmds = n; > + > + ret = __rpmh_write(dev, state, &rpm_msg); > + if (ret) > + return ret; > + > + ret = wait_for_completion_timeout(&compl, RPMH_TIMEOUT_MS); IMO it's almost never a good idea to use wait_for_completion_timeout() together with a completion that's declared on the stack. If you somehow insist that this is a good idea then I need to see incredibly clear and obvious code/comments that say why it's impossible that the process might somehow try to signal the completion _after_ RPMH_TIMEOUT_MS has expired. Specifically if the timeout happens but the process could still signal a completion later then they will access random data on the stack of a function that has already returned. This causes ridiculously difficult-to-debug crashes. NOTE: You've got timeout set to 10 seconds here. Is that really even useful? IMO just call wait_for_completion() without a timeout. It's much better to have a nice clean hang than a random stack corruption. -Doug