From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754915AbbCRPT3 (ORCPT ); Wed, 18 Mar 2015 11:19:29 -0400 Received: from forward18.mail.yandex.net ([95.108.253.143]:38999 "EHLO forward18.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753764AbbCRPT1 (ORCPT ); Wed, 18 Mar 2015 11:19:27 -0400 From: Evgeniy Polyakov Envelope-From: drustafa@yandex.ru To: David Fries Cc: Thorsten Bschorr , Jonathan ALIBERT , "linux-kernel@vger.kernel.org" In-Reply-To: <20150318042037.GE21067@spacedout.fries.net> References: <20150301021744.GW6151@spacedout.fries.net> <20150302001713.GA6151@spacedout.fries.net> <4333121425483401@web21m.yandex.ru> <20150308211449.GG11991@spacedout.fries.net> <20150309230924.GJ11991@spacedout.fries.net> <2663771425995520@web30h.yandex.ru> <20150312005408.GD23778@spacedout.fries.net> <2283421426366516@web2o.yandex.ru> <20150318042037.GE21067@spacedout.fries.net> Subject: Re: [PATCH] Avoid null-pointer access in w1/slaves/w1_therm MIME-Version: 1.0 Message-Id: <702441426691933@web2g.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Wed, 18 Mar 2015 18:18:53 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi 18.03.2015, 07:20, "David Fries" : > šstatic void w1_therm_remove_slave(struct w1_slave *sl) > š{ > + int refcnt = atomic_sub_return(1, THERM_REFCNT(sl->family_data)); > + while(refcnt) { > + msleep(1000); > + refcnt = atomic_read(THERM_REFCNT(sl->family_data)); > + } > ššššššššškfree(sl->family_data); > šššššššššsl->family_data = NULL; > š} Can we replace this whole atomic manipulations with kref_t and free family data in the place which actually drops reference counter to zero? I.e. we return from remove_slave() function potentially leaving family data floating around, it will be freed when the last user drops the reference. There is still a race between increasing reference when starting reading and removing slave device, i.e. one starts reading, while attached slave device is being removed, but that's a different problem.