lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGTfZH3d4La5Rtcd4abXUXuPhPX6x6g2PaP7tiRMDkqPvscRxA@mail.gmail.com>
Date:	Fri, 25 Apr 2014 00:10:41 +0900
From:	Chanwoo Choi <cwchoi00@...il.com>
To:	Felipe Balbi <balbi@...com>
Cc:	Chanwoo Choi <cw00.choi@...sung.com>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	"myungjoo.ham@...sung.com" <myungjoo.ham@...sung.com>,
	gg@...mlogic.co.uk, Kishon Vijay Abraham I <kishon@...com>,
	ckeepax@...nsource.wolfsonmicro.com,
	Mark Brown <broonie@...nel.org>,
	Krzysztof Kozlowski <k.kozlowski@...sung.com>,
	Kyungmin Park <kyungmin.park@...sung.com>
Subject: Re: [PATCHv3 2/9] extcon: Add devm_extcon_dev_allocate/free to manage
 the resource of extcon device

On Fri, Apr 25, 2014 at 12:06 AM, Felipe Balbi <balbi@...com> wrote:
> Hi,
>
> On Fri, Apr 25, 2014 at 12:03:31AM +0900, Chanwoo Choi wrote:
>> On Thu, Apr 24, 2014 at 11:44 PM, Felipe Balbi <balbi@...com> wrote:
>> > On Thu, Apr 24, 2014 at 09:34:50PM +0900, Chanwoo Choi wrote:
>> >> This patch add device managed devm_extcon_dev_{allocate,free} to automatically
>> >> free the memory of extcon_dev structure without handling free operation.
>> >>
>> >> Signed-off-by: Chanwoo Choi <cw00.choi@...sung.com>
>> >> ---
>> >>  drivers/extcon/extcon-class.c | 70 +++++++++++++++++++++++++++++++++++--------
>> >>  include/linux/extcon.h        | 11 +++++++
>> >>  2 files changed, 69 insertions(+), 12 deletions(-)
>> >>
>> >> diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
>> >> index bec66d4..f369168 100644
>> >> --- a/drivers/extcon/extcon-class.c
>> >> +++ b/drivers/extcon/extcon-class.c
>> >> @@ -604,6 +604,64 @@ void extcon_dev_free(struct extcon_dev *edev)
>> >>  }
>> >>  EXPORT_SYMBOL_GPL(extcon_dev_free);
>> >>
>> >> +static int devm_extcon_dev_match(struct device *dev, void *res, void *data)
>> >> +{
>> >> +     struct extcon_dev **r = res;
>> >> +
>> >> +     if (!r || !*r) {
>> >> +             WARN_ON(!r || !*r);
>> >> +             return 0;
>> >> +     }
>> >> +
>> >> +     return *r == data;
>> >> +}
>> >> +
>> >> +static void devm_extcon_dev_release(struct device *dev, void *res)
>> >> +{
>> >> +     extcon_dev_free(*(struct extcon_dev **)res);
>> >> +}
>> >> +
>> >> +/**
>> >> + * devm_extcon_dev_allocate - Allocate managed extcon device
>> >> + * @dev:             device owning the extcon device being created
>> >> + * @supported_cable: Array of supported cable names ending with NULL.
>> >> + *                   If supported_cable is NULL, cable name related APIs
>> >> + *                   are disabled.
>> >> + *
>> >> + * This function manages automatically the memory of extcon device using device
>> >> + * resource management and simplify the control of freeing the memory of extcon
>> >> + * device.
>> >> + *
>> >> + * Returns the pointer memory of allocated extcon_dev if success or NULL if fail
>> >> + */
>> >> +struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
>> >> +                                         const char **supported_cable)
>> >> +{
>> >> +     struct extcon_dev **ptr, *edev;
>> >> +
>> >> +     ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL);
>> >> +     if (!ptr)
>> >> +             return NULL;
>> >
>> > if this fails you return NULL;
>> >
>> >> +
>> >> +     edev = extcon_dev_allocate(supported_cable);
>> >
>> > if this fails, you return -ENOMEM. Not very nice, if you ask me.
>>
>> I'll fix it as following:
>>
>> If  both extcon_dev_allocate() and devm_excon_dev_allocate() failed to
>> allocate memory,
>> two functions would return NULL pointer instead of  ERR_PTR(-ENOMEM).
>
> your call, I'd rather see them both returning ERR_PTR(-ENOMEM), but no
> strong feelings.

OK, I'll fix it as your comment.

Thanks,
Chanwoo Choi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ