From patchwork Thu Apr 1 15:54:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 3076 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Thu, 01 Apr 2010 15:54:53 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Thu, 01 Apr 2010 12:58:53 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NxMjN-0002Zo-9s; Thu, 01 Apr 2010 15:54:53 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757048Ab0DAPyu (ORCPT + 1 other); Thu, 1 Apr 2010 11:54:50 -0400 Received: from mail-bw0-f209.google.com ([209.85.218.209]:46480 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756998Ab0DAPys (ORCPT ); Thu, 1 Apr 2010 11:54:48 -0400 Received: by bwz1 with SMTP id 1so951609bwz.21 for ; Thu, 01 Apr 2010 08:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mail-followup-to:mime-version:content-type :content-disposition:user-agent; bh=bB4pDdLlsfbUiGPo1prNdNVgXhOwY+cfw7i1ho2ZAt0=; b=avfGvYtCqEBDNvQKCJ0jmqLuTShsan4fUGEp1ACzPe6CkPq0qYiOGgVTRu1Axkjr75 C3Wwbx9sE6cYcZBv81w2gjcHcnDOuiWaOYKP3/Rzj3ujO7oPZ2fFGGGqnKfmqn6Ptqi6 M0Pa1Q+3veyO9KIymchl+RNxMxNS2I/AZpBrA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; b=MkXUWczcITwp4r1Vi6G4DfUZj9oiSooGZlMbvJheXD1Z8sC/PDSKH3rLRIkqn+bXwK ywBiWN5pjIO6WCrvXwMTn1AuWOLaeDGyE4WFuWxasK3z6Wo5yriFTEpZn6BoC1FV5Pk3 Iv4tlbDR1anWfW2e2HKJCiRGy7jQfLPByYb9A= Received: by 10.204.34.195 with SMTP id m3mr1611667bkd.190.1270137286874; Thu, 01 Apr 2010 08:54:46 -0700 (PDT) Received: from bicker ([196.43.68.55]) by mx.google.com with ESMTPS id 24sm68181597bkr.6.2010.04.01.08.54.42 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 01 Apr 2010 08:54:45 -0700 (PDT) Date: Thu, 1 Apr 2010 18:54:38 +0300 From: Dan Carpenter To: Mauro Carvalho Chehab Cc: Dmitry Torokhov , =?iso-8859-1?Q?M=E1rton_N=E9meth?= , Alexander Beregalov , Matthew Garrett , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] ir-keytable: avoid double lock Message-ID: <20100401155438.GE5265@bicker> Mail-Followup-To: Dan Carpenter , Mauro Carvalho Chehab , Dmitry Torokhov , =?iso-8859-1?Q?M=E1rton_N=E9meth?= , Alexander Beregalov , Matthew Garrett , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org It's possible that we wanted to resize to a smaller size but we didn't have enough memory to create the new table. We need to test for that here so we don't try to lock twice and dead lock. Also we free the "oldkeymap" on that path and that would be bad. Signed-off-by: Dan Carpenter --- I don't know this code very well. Maybe we should just take the lock earlier in the function for the resize case and the non resize case. Can we add new keys while the resize is taking place? -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 0a3b4ed..51cd0f3 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c @@ -216,7 +216,7 @@ static void ir_delete_key(struct ir_scancode_table *rc_tab, int elem) memcpy(&newkeymap[elem], &oldkeymap[elem + 1], (newsize - elem) * sizeof(*newkeymap)); - if (resize) { + if (resize && newkeymap != oldkeymap) { /* * As the copy happened to a temporary table, only here * it needs to lock while replacing the table pointers