Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp576042ybp; Fri, 4 Oct 2019 01:19:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaMhe0sLCLjjno4Rc6L2JoEImgNpk96VQYZLwObzsUodozCbb4J0+DVnXV7mqn488huKGo X-Received: by 2002:aa7:c1d4:: with SMTP id d20mr13670796edp.223.1570177183520; Fri, 04 Oct 2019 01:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570177183; cv=none; d=google.com; s=arc-20160816; b=knmVK+xZl70mEfogq22aT4OCE0aQGEwRjjwO+PXq/C2huWJinwXT5gEjsVa3KerG0a ljl+q9tlMS/KPGD4OZZlnW6/ALeJOCqUD1W/RUM9sBm12VZGELn+Irdt+fc1I6rPBIS2 qHhY7Z8xWEqiXf8cmGCicWku1HbcouUQvcKTxvlgQf5DL27zfT9mSOTKAWNV+GXjw7QF eLepOPpKSpa7Nk3r71XncvBXArJTf2LclvU2mWLWW15M7NyQWTjfx16forZPMNmO8x5m xjBoswZ0tQJTxIfvZ/lBNjxWiNpCHXJX1n0n0wNQRcfp4sNCJvnbQXRFfOTRre6Ir7wz 63NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=unJ1v6HVKxuDiPc/aS201QU9G4bHdnBp/CHw6DE6gKk=; b=QJnnKTYEFMHV/d95/KtIZ07oU3UqQRxsvn/m41iZGQX0POoTnYmY9NHES448iA3fCU d0k99eMiNgATXh9GIiwSkEsO8U2dbdqzMpeSzGxeJs1RMLcKqyv+Om5cD8DJcyHB3goL twR9mw5NHOgP0IEjpW7Tgg6c+U1XFx0ZuNbzYhjfoEfYJqCfA0mrDW3YQIfqp843p4OF kbXWlNddvnSWGiCWqx9ySWF2okudrOu6lcz3aVkNMsiUk1n5J8zZTj3+AOve0SP8bJ+0 EwZpB5kISRruRJx9qjTrcsbr4HTrpJydJWr3o/lzeKlb3WuIjRwGya2r3ARNS+pd7Lw+ V7dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rJyVp4pR; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b16si2749442ejb.165.2019.10.04.01.19.18; Fri, 04 Oct 2019 01:19:43 -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=@linaro.org header.s=google header.b=rJyVp4pR; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731637AbfJDFvB (ORCPT + 99 others); Fri, 4 Oct 2019 01:51:01 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44076 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731388AbfJDFvB (ORCPT ); Fri, 4 Oct 2019 01:51:01 -0400 Received: by mail-pg1-f195.google.com with SMTP id i14so3092361pgt.11 for ; Thu, 03 Oct 2019 22:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=unJ1v6HVKxuDiPc/aS201QU9G4bHdnBp/CHw6DE6gKk=; b=rJyVp4pRytBy0bcdhLCHyuZczSU3u3NXL75qLt2S963EyjEQ1ZMcT8MJAa6qWY2nDI HluMh/daIYQuIRVBhTAGrJcsSGiwPLHju1/+GPKnDxCJGnadJK2rfgDKt2qf9qHypvk0 xw3o1TADQ5k7Jn365mGwDTlLxyhnF8I3afLp9BfV3VAe5rbSIQjk3phhVVmN2LdZktcQ fPeIPaximdKA/5SI+l1HJfevuqsMdgOueH+bJQ/KzTHSxXJDmpewLTsWAwrr9ZA/guuQ /j1FBHdNKs6h/uClA9iAzNIQCBlshZonQBpz218FHo2t/IrP7WMFwXQNjorwuzVL0W4v CVKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=unJ1v6HVKxuDiPc/aS201QU9G4bHdnBp/CHw6DE6gKk=; b=BBUa6iXP5N66siBj2h0wRnivfBkL9eoivJEQ2yPd4fabrbJS9M7Sj+ppFagoOkNkuI CrhkloOKoeP+NAYluBstVKWWzNS8lCoUBoF/KraUrQhrvUm/zWPfTDuLz1m8HhndghC+ 5BzTTbD5Nh7S+bynCO2ysk81PlQKKey9lx4abJ0KQhdqANwWcJpEZGWeRbegXqCrgG3d aUAkr5oHC0nrK+k851jzn/aHNZb2iEUgjFtXpbvXovbEZnX4WP/kL0bS7TESl20Cn1rQ NjCVt3YbL847kYZACUxYTPEjoiOdJdQbKIVQh4TsxvO8g2AMhiRwi6vCm6Y/esPzoz7s 4EPg== X-Gm-Message-State: APjAAAWnyutA668eUrL3GcLyq0gnUGNUocge3+j8XN8wZeyAhQpGTGnC HV39Dv5P4oi5qfNN5fGzDW3WZg== X-Received: by 2002:a17:90a:fe04:: with SMTP id ck4mr15107769pjb.74.1570168260323; Thu, 03 Oct 2019 22:51:00 -0700 (PDT) Received: from minitux (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id h8sm5111262pfo.64.2019.10.03.22.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2019 22:50:59 -0700 (PDT) Date: Thu, 3 Oct 2019 22:50:57 -0700 From: Bjorn Andersson To: Stephen Boyd Cc: Murali Nalajala , gregkh@linuxfoundation.org, rafael@kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] base: soc: Handle custom soc information sysfs entries Message-ID: <20191004055057.GH63675@minitux> References: <1570146710-13503-1-git-send-email-mnalajal@codeaurora.org> <5d96daca.1c69fb81.fe5e4.e623@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d96daca.1c69fb81.fe5e4.e623@mx.google.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 03 Oct 22:38 PDT 2019, Stephen Boyd wrote: > Quoting Murali Nalajala (2019-10-03 16:51:50) > > @@ -151,14 +156,16 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr > > > > ret = device_register(&soc_dev->dev); > > if (ret) > > - goto out3; > > + goto out4; > > > > return soc_dev; > > > > -out3: > > +out4: > > ida_simple_remove(&soc_ida, soc_dev->soc_dev_num); > > put_device(&soc_dev->dev); > > soc_dev = NULL; > > +out3: > > + kfree(soc_attr_groups); > > This code is tricky. put_device(&soc_dev->dev) will call soc_release() > so we set soc_dev to NULL before calling kfree() on the error path. This > way we don't doubly free a pointer that the release function will take > care of. I wonder if the release function could free the ida as well, > and then we could just make the device_register() failure path call > put_device() and return ERR_PTR(ret) directly. Then the error path is > simpler because we can avoid changing two pointers to NULL to avoid the > double free twice. Or just inline the ida remove and put_device() call > in the if and then goto out1 to consolidate the error pointer > conversion. > But if we instead allocates the ida before the soc_dev, wouldn't the error path be something like?: foo: put_device(&soc_dev->dev); bar: ida_simple_remove(&soc_ida, soc_num); return err; I think we still need two exit paths from soc_device_register() regardless of moving the ida_simple_remove() into the release, but we could drop it from the unregister(). So not sure if this is cleaner... Regards, Bjorn > > out2: > > kfree(soc_dev); > > out1: